the input fields for data name had an inconsistant limit for input fields, making...
[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                 allqueue(REDRAWVIEW3D, 0);
1741                 allqueue(REDRAWBUTSOBJECT, 0);
1742                 break;
1743         case B_DUPLI_FACES:
1744                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
1745                 allqueue(REDRAWVIEW3D, 0);
1746                 allqueue(REDRAWBUTSOBJECT, 0);
1747                 break;
1748         case B_DUPLI_GROUP:
1749                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
1750                 allqueue(REDRAWVIEW3D, 0);
1751                 allqueue(REDRAWBUTSOBJECT, 0);
1752                 break;
1753                 
1754         case B_PRINTSPEED:
1755                 {
1756                         float vec[3];
1757                         CFRA++;
1758                         do_ob_ipo(ob);
1759                         where_is_object(ob);
1760                         VECCOPY(vec, ob->obmat[3]);
1761                         CFRA--;
1762                         do_ob_ipo(ob);
1763                         where_is_object(ob);
1764                         VecSubf(vec, vec, ob->obmat[3]);
1765                         prspeed= Normalize(vec);
1766                         scrarea_queue_winredraw(curarea);
1767                 }
1768                 break;
1769         case B_PRINTLEN:
1770                 if(ob->type==OB_CURVE) {
1771                         Curve *cu=ob->data;
1772                         
1773                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
1774                         scrarea_queue_winredraw(curarea);
1775                 } 
1776                 break;
1777         case B_RELKEY:
1778                 allspace(REMAKEIPO, 0);
1779                 allqueue(REDRAWBUTSOBJECT, 0);
1780                 allqueue(REDRAWBUTSEDIT, 0);
1781                 allqueue(REDRAWIPO, 0);
1782                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1783                 break;
1784         case B_CURVECHECK:
1785                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1786                 allqueue(REDRAWVIEW3D, 0);
1787                 break;
1788         
1789         case B_SOFTBODY_CHANGE:
1790                 ob->softflag |= OB_SB_REDO;
1791                 allqueue(REDRAWBUTSOBJECT, 0);
1792                 allqueue(REDRAWVIEW3D, 0);
1793                 break;
1794         case B_SOFTBODY_DEL_VG:
1795                 if(ob->soft) {
1796                         ob->soft->vertgroup= 0;
1797                         ob->softflag |= OB_SB_REDO;
1798                         allqueue(REDRAWBUTSOBJECT, 0);
1799                         allqueue(REDRAWVIEW3D, 0);
1800                 }
1801                 break;
1802         case B_SOFTBODY_BAKE:
1803                 if(ob->soft) softbody_bake(ob);
1804                 break;
1805         case B_SOFTBODY_BAKE_FREE:
1806                 if(ob->soft) sbObjectToSoftbody(ob);
1807                 allqueue(REDRAWBUTSOBJECT, 0);
1808                 allqueue(REDRAWVIEW3D, 0);
1809                 break;
1810         case B_FLUIDSIM_BAKE:
1811                 /* write config files (currently no simulation) */
1812                 fluidsimBake(ob);
1813                 break;
1814         case B_FLUIDSIM_MAKEPART:
1815                 {
1816                         PartEff *paf= NULL;
1817                         /* prepare fluidsim particle display */
1818                         // simplified delete effect, create new - recalc some particles...
1819                         if(ob==NULL || ob->type!=OB_MESH) break;
1820                         ob->fluidsimSettings->type = 0;
1821                         // reset type, and init particle system once normally
1822                         paf= give_parteff(ob); 
1823                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
1824                             (!paf)) { 
1825                                 // create new entry
1826                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
1827                         paf = give_parteff(ob);
1828                         if(paf) {
1829                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
1830                                 build_particle_system(ob);
1831                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
1832                         }
1833                 }
1834                 allqueue(REDRAWVIEW3D, 0);
1835                 allqueue(REDRAWBUTSOBJECT, 0);
1836                 break;
1837         case B_FLUIDSIM_SELDIR: 
1838                 {
1839                         ScrArea *sa = closest_bigger_area();
1840                         /* choose dir for surface files */
1841                         areawinset(sa->win);
1842                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
1843                 }
1844                 break;
1845         case B_FLUIDSIM_FORCEREDRAW:
1846                 /* force redraw */
1847                 allqueue(REDRAWBUTSOBJECT, 0);
1848                 allqueue(REDRAWVIEW3D, 0);
1849                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1850                 break;
1851         case B_GROUP_RELINK:
1852                 group_relink_nla_objects(ob);
1853                 allqueue(REDRAWVIEW3D, 0);
1854                 break;
1855                 
1856         default:
1857                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1858                         int a=B_SELEFFECT;
1859                         
1860                         eff= ob->effect.first;
1861                         while(eff) {
1862                                 if(event==a) eff->flag |= SELECT;
1863                                 else eff->flag &= ~SELECT;
1864                                 
1865                                 a++;
1866                                 eff= eff->next;
1867                         }
1868                         allqueue(REDRAWBUTSOBJECT, 0);
1869                 }
1870         }
1871
1872 }
1873
1874 static void do_add_groupmenu(void *arg, int event)
1875 {
1876         Object *ob= OBACT;
1877         
1878         if(ob) {
1879                 
1880                 if(event== -1) {
1881                         Group *group= add_group( "Group" );
1882                         add_to_group(group, ob);
1883                 }
1884                 else
1885                         add_to_group(BLI_findlink(&G.main->group, event), ob);
1886                         
1887                 ob->flag |= OB_FROMGROUP;
1888                 BASACT->flag |= OB_FROMGROUP;
1889                 allqueue(REDRAWBUTSOBJECT, 0);
1890                 allqueue(REDRAWVIEW3D, 0);
1891         }               
1892 }
1893
1894 static uiBlock *add_groupmenu(void *arg_unused)
1895 {
1896         uiBlock *block;
1897         Group *group;
1898         short yco= 0;
1899         char str[32];
1900         
1901         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1902         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1903
1904         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1905         for(group= G.main->group.first; group; group= group->id.next, yco++) {
1906                 if(group->id.lib) strcpy(str, "L  ");
1907                 else strcpy(str, "   ");
1908                 strcat(str, group->id.name+2);
1909                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
1910         }
1911         
1912         uiTextBoundsBlock(block, 50);
1913         uiBlockSetDirection(block, UI_DOWN);    
1914         
1915         return block;
1916 }
1917
1918 static void group_ob_rem(void *gr_v, void *ob_v)
1919 {
1920         Object *ob= OBACT;
1921         
1922         rem_from_group(gr_v, ob);
1923         if(find_group(ob)==NULL) {
1924                 ob->flag &= ~OB_FROMGROUP;
1925                 BASACT->flag &= ~OB_FROMGROUP;
1926         }
1927         allqueue(REDRAWBUTSOBJECT, 0);
1928         allqueue(REDRAWVIEW3D, 0);
1929
1930 }
1931
1932 static void group_local(void *gr_v, void *unused)
1933 {
1934         Group *group= gr_v;
1935         
1936         group->id.lib= NULL;
1937         
1938         allqueue(REDRAWBUTSOBJECT, 0);
1939         allqueue(REDRAWVIEW3D, 0);
1940         
1941 }
1942
1943 static void object_panel_object(Object *ob)
1944 {
1945         uiBlock *block;
1946         uiBut *but;
1947         Group *group;
1948         int a, xco, yco=0;
1949         short dx= 33, dy= 30;
1950
1951         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
1952         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
1953         
1954         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
1955         
1956         /* object name */
1957         uiBlockSetCol(block, TH_BUT_SETTING2);
1958         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);
1959         uiBlockSetCol(block, TH_AUTO);
1960         
1961         /* parent */
1962         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
1963         
1964         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.");
1965
1966         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1967
1968         /* all groups */
1969         for(group= G.main->group.first; group; group= group->id.next) {
1970                 if(object_in_group(ob, group)) {
1971                         xco= 160;
1972                         
1973                         uiBlockBeginAlign(block);
1974                         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.");
1975                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1976                         
1977                         if(group->id.lib) {
1978                                 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");
1979                                 uiButSetFunc(but, group_local, group, NULL);
1980                                 xco= 180;
1981                         }
1982                         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");
1983                         uiButSetFunc(but, group_ob_rem, group, ob);
1984                         
1985                         yco+= 20;
1986                         xco= 10;
1987                         
1988                         /* layers */
1989                         uiBlockBeginAlign(block);
1990                         for(a=0; a<5; a++)
1991                                 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, "");
1992                         for(a=0; a<5; a++)
1993                                 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, "");
1994                         
1995                         xco+= 7;
1996                         uiBlockBeginAlign(block);
1997                         for(a=5; a<10; a++)
1998                                 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, "");
1999                         for(a=5; a<10; a++)
2000                                 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, "");
2001                         
2002                         uiBlockEndAlign(block);
2003                         
2004                         yco+= 40;
2005                 }
2006         }
2007         
2008         if(120-yco < -10)
2009                 uiNewPanelHeight(block, 204 - (120-yco));
2010 }
2011
2012 static void object_panel_anim(Object *ob)
2013 {
2014         uiBlock *block;
2015         char str[32];
2016         
2017         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2018         if(uiNewPanel(curarea, block, "Anim settings", "Object", 320, 0, 318, 204)==0) return;
2019         
2020         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2021         
2022         uiBlockBeginAlign(block);
2023         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");
2024         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");
2025         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");
2026         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");
2027         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");
2028         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");
2029         uiBlockBeginAlign(block);
2030         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,180,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
2031         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,180,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
2032         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,180,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
2033         
2034         uiBlockBeginAlign(block);
2035         uiDefButBitS(block, TOG, OB_DRAWKEY, REDRAWVIEW3D, "Draw Key",          24,155,71,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
2036         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");
2037         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,155,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
2038         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,155,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
2039         uiBlockBeginAlign(block);
2040         
2041         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");
2042         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");
2043         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");
2044         uiDefButBitS(block, TOG, OB_DUPLIGROUP, B_DUPLI_GROUP, "DupliGroup",            24,110,150,20, &ob->transflag, 0, 0, 0, 0, "Enable group instancing");
2045         if(ob->transflag & OB_DUPLIFRAMES)
2046                 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");
2047         else if(ob->transflag & OB_DUPLIVERTS)
2048                 uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",                              174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to vertex normal");
2049         else if(ob->transflag & OB_DUPLIFACES)
2050                 uiDefButBitS(block, TOG, OB_DUPLIFACES_SCALE, REDRAWVIEW3D, "Scale",                    174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Scale dupli based on face size");
2051         else
2052                 uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_GROUP_RELINK, "GR:", 174,110,142,20, &ob->dup_group, "Instance an existing group");
2053
2054         uiBlockBeginAlign(block);
2055         /* DupSta and DupEnd are both shorts, so the maxframe is greater then their range
2056         just limit the buttons to the max short */
2057         uiDefButI(block, NUM, REDRAWVIEW3D, "DupSta:",          24,85,141,19, &ob->dupsta, 1.0, 32767, 0, 0, "Specify startframe for Dupliframes");
2058         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");
2059         uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
2060         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");
2061         uiBlockBeginAlign(block);
2062         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
2063         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");
2064         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");
2065         
2066         uiBlockBeginAlign(block);
2067         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
2068         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,10,104,20, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
2069         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,10,67,20, 0, 0, 0, 0, 0, "Print objectspeed");
2070         uiBlockEndAlign(block);
2071         
2072         sprintf(str, "%.4f", prspeed);
2073         uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
2074         
2075 }
2076
2077 static void object_panel_draw(Object *ob)
2078 {
2079         uiBlock *block;
2080         int xco, a, dx, dy;
2081         
2082         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
2083         if(uiNewPanel(curarea, block, "Draw", "Object", 640, 0, 318, 204)==0) return;
2084         
2085         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2086         
2087         /* LAYERS */
2088         xco= 120;
2089         dx= 35;
2090         dy= 30;
2091         
2092         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2093         
2094         uiBlockBeginAlign(block);
2095         for(a=0; a<5; a++)
2096                 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, "");
2097         for(a=0; a<5; a++)
2098                 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, "");
2099         
2100         xco+= 7;
2101         uiBlockBeginAlign(block);
2102         for(a=5; a<10; a++)
2103                 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, "");
2104         for(a=5; a<10; a++)
2105                 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, "");
2106         
2107         uiBlockEndAlign(block);
2108         
2109         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
2110         
2111         uiBlockBeginAlign(block);
2112         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
2113         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
2114         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
2115         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
2116         uiBlockEndAlign(block);
2117         
2118         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
2119         
2120         uiBlockBeginAlign(block);
2121         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
2122         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
2123         
2124         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
2125                           120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2126         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");
2127         
2128         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
2129         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");
2130         
2131         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)");
2132         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");
2133         
2134 }
2135
2136 void object_panel_constraint(char *context)
2137 {
2138         uiBlock *block;
2139         Object *ob= OBACT;
2140         ListBase *conlist;
2141         bConstraint *curcon;
2142         short xco, yco;
2143         char str[64];
2144         
2145         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
2146         if(uiNewPanel(curarea, block, "Constraints", context, 960, 0, 318, 204)==0) return;
2147         
2148         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2149         
2150         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2151         /* so first we make it default height */
2152         uiNewPanelHeight(block, 204);
2153         
2154         if(G.obedit==OBACT) return;     // ??
2155         
2156         conlist = get_active_constraints(OBACT);
2157         
2158         if (conlist) {
2159                 
2160                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint", 0, 190, 130, 20, "Add a new constraint");
2161                 
2162                 /* print active object or bone */
2163                 str[0]= 0;
2164                 if (ob->flag & OB_POSEMODE){
2165                         bPoseChannel *pchan= get_active_posechannel(ob);
2166                         if(pchan) sprintf(str, "To Bone: %s", pchan->name);
2167                 }
2168                 else {
2169                         sprintf(str, "To Object: %s", ob->id.name+2);
2170                 }
2171                 uiDefBut(block, LABEL, 1, str,  150, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Displays Active Object or Bone name");
2172                 
2173                 /* Go through the list of constraints and draw them */
2174                 xco = 10;
2175                 yco = 160;
2176                 
2177                 for (curcon = conlist->first; curcon; curcon=curcon->next) {
2178                         /* hrms, the temporal constraint should not draw! */
2179                         if(curcon->type==CONSTRAINT_TYPE_KINEMATIC) {
2180                                 bKinematicConstraint *data= curcon->data;
2181                                 if(data->flag & CONSTRAINT_IK_TEMP)
2182                                         continue;
2183                         }
2184                         /* Draw default constraint header */
2185                         draw_constraint(block, conlist, curcon, &xco, &yco);    
2186                 }
2187                 
2188                 if(yco < 0) uiNewPanelHeight(block, 204-yco);
2189                 
2190         }
2191 }
2192
2193 void do_effects_panels(unsigned short event)
2194 {
2195         Object *ob;
2196         Base *base;
2197         Effect *eff, *effn;
2198         PartEff *paf;
2199         
2200         ob= OBACT;
2201
2202         switch(event) {
2203
2204     case B_AUTOTIMEOFS:
2205                 auto_timeoffs();
2206                 break;
2207         case B_FRAMEMAP:
2208                 G.scene->r.framelen= G.scene->r.framapto;
2209                 G.scene->r.framelen/= G.scene->r.images;
2210                 allqueue(REDRAWALL, 0);
2211                 break;
2212         case B_NEWEFFECT:
2213                 if(ob) {
2214                         if(ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) { 
2215                                 // NT particles and fluid meshes currently dont work together -> switch off beforehand
2216                                 if(ob->fluidsimSettings->type == OB_FLUIDSIM_DOMAIN) {
2217                                         pupmenu("Fluidsim Particle Error%t|Please disable the fluidsim domain before activating particles.%x0");
2218                                         break;
2219                                         //ob->fluidsimFlag = 0; ob->fluidsimSettings->type = 0; allqueue(REDRAWVIEW3D, 0); 
2220                                 }
2221                         }
2222                         if (BLI_countlist(&ob->effect)==MAX_EFFECT)
2223                                 error("Unable to add: effect limit reached");
2224                         else
2225                                 copy_act_effect(ob);
2226                 }
2227                 DAG_scene_sort(G.scene);
2228                 BIF_undo_push("New effect");
2229                 allqueue(REDRAWBUTSOBJECT, 0);
2230                 break;
2231         case B_DELEFFECT:
2232                 if(ob==NULL || ob->type!=OB_MESH) break;
2233                 eff= ob->effect.first;
2234                 while(eff) {
2235                         effn= eff->next;
2236                         if(eff->flag & SELECT) {
2237                                 BLI_remlink(&ob->effect, eff);
2238                                 free_effect(eff);
2239                                 break;
2240                         }
2241                         eff= effn;
2242                 }
2243                 BIF_undo_push("Delete effect");
2244                 allqueue(REDRAWVIEW3D, 0);
2245                 allqueue(REDRAWBUTSOBJECT, 0);
2246                 break;
2247         case B_NEXTEFFECT:
2248                 if(ob==0 || ob->type!=OB_MESH) break;
2249                 eff= ob->effect.first;
2250                 while(eff) {
2251                         if(eff->flag & SELECT) {
2252                                 if(eff->next) {
2253                                         eff->flag &= ~SELECT;
2254                                         eff->next->flag |= SELECT;
2255                                 }
2256                                 break;
2257                         }
2258                         eff= eff->next;
2259                 }
2260                 allqueue(REDRAWBUTSOBJECT, 0);
2261                 break;
2262         case B_PREVEFFECT:
2263                 if(ob==0 || ob->type!=OB_MESH) break;
2264                 eff= ob->effect.first;
2265                 while(eff) {
2266                         if(eff->flag & SELECT) {
2267                                 if(eff->prev) {
2268                                         eff->flag &= ~SELECT;
2269                                         eff->prev->flag |= SELECT;
2270                                 }
2271                                 break;
2272                         }
2273                         eff= eff->next;
2274                 }
2275                 allqueue(REDRAWBUTSOBJECT, 0);
2276                 break;
2277         case B_EFFECT_DEP:
2278                 DAG_scene_sort(G.scene);
2279                 /* no break, pass on */
2280         case B_CALCEFFECT:
2281                 if(ob==NULL || ob->type!=OB_MESH) break;
2282                 eff= ob->effect.first;
2283                 while(eff) {
2284                         if(eff->flag & SELECT) {
2285                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2286                         }
2287                         eff= eff->next;
2288                 }
2289                 allqueue(REDRAWVIEW3D, 0);
2290                 allqueue(REDRAWBUTSOBJECT, 0);
2291                 break;
2292         case B_PAF_SET_VG:
2293                 
2294                 paf= give_parteff(ob);
2295                 if(paf) {
2296                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname);
2297                         if(dg)
2298                                 paf->vertgroup= get_defgroup_num(ob, dg)+1;
2299                         else
2300                                 paf->vertgroup= 0;
2301                         
2302                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2303                         allqueue(REDRAWVIEW3D, 0);
2304                 }
2305                 break;
2306         case B_PAF_SET_VG1:
2307                 
2308                 paf= give_parteff(ob);
2309                 if(paf) {
2310                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname_v);
2311                         if(dg)
2312                                 paf->vertgroup_v= get_defgroup_num(ob, dg)+1;
2313                         else
2314                                 paf->vertgroup_v= 0;
2315                         
2316                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2317                         allqueue(REDRAWVIEW3D, 0);
2318                 }
2319                 break;
2320         case B_FIELD_DEP:
2321                 /* do this before scene sort, that one checks for CU_PATH */
2322                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE) {
2323                         Curve *cu= ob->data;
2324                         
2325                         cu->flag |= (CU_PATH|CU_3D);
2326                         do_curvebuts(B_CU3D);   /* all curves too */
2327                 }
2328                 DAG_scene_sort(G.scene);
2329
2330                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE)
2331                         DAG_object_flush_update(G.scene, ob, OB_RECALC);
2332                 else
2333                         DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2334
2335                 allqueue(REDRAWVIEW3D, 0);
2336                 allqueue(REDRAWBUTSOBJECT, 0);
2337                 break;
2338         case B_FIELD_CHANGE:
2339                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2340                 allqueue(REDRAWVIEW3D, 0);
2341                 break;
2342         case B_RECALCAL:
2343                 if (G.vd==NULL)
2344                         break;
2345                 
2346                 base= FIRSTBASE;
2347                 while(base) {
2348                         if(base->lay & G.vd->lay) {
2349                                 ob= base->object;
2350                                 eff= ob->effect.first;
2351                                 while(eff) {
2352                                         if(eff->flag & SELECT) {
2353                                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2354                                         }
2355                                         eff= eff->next;
2356                                 }
2357                         }
2358                         base= base->next;
2359                 }
2360                 allqueue(REDRAWVIEW3D, 0);
2361                 break;
2362         default:
2363                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2364                         ob= OBACT;
2365                         if(ob) {
2366                                 int a=B_SELEFFECT;
2367                                 
2368                                 eff= ob->effect.first;
2369                                 while(eff) {
2370                                         if(event==a) eff->flag |= SELECT;
2371                                         else eff->flag &= ~SELECT;
2372                                         
2373                                         a++;
2374                                         eff= eff->next;
2375                                 }
2376                                 allqueue(REDRAWBUTSOBJECT, 0);
2377                         }
2378                 }
2379         }
2380
2381 }
2382
2383 /* Panel for particle interaction settings */
2384 static void object_panel_fields(Object *ob)
2385 {
2386         uiBlock *block;
2387
2388         block= uiNewBlock(&curarea->uiblocks, "object_panel_fields", UI_EMBOSS, UI_HELV, curarea->win);
2389         if(uiNewPanel(curarea, block, "Fields and Deflection", "Physics", 0, 0, 318, 204)==0) return;
2390
2391         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2392         
2393         /* should become button, option? */
2394         if(ob->pd==NULL) {
2395                 ob->pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
2396                 /* and if needed, init here */
2397                 ob->pd->pdef_sbdamp = 0.1f;
2398                 ob->pd->pdef_sbift  = 0.2f;
2399                 ob->pd->pdef_sboft  = 0.02f;
2400         }
2401         
2402         if(ob->pd) {
2403                 PartDeflect *pd= ob->pd;
2404                 char *menustr= MEM_mallocN(256, "temp string");
2405                 char *tipstr="Choose field type";
2406                 
2407                 uiDefBut(block, LABEL, 0, "Fields",             10,180,140,20, NULL, 0.0, 0, 0, 0, "");
2408                 
2409                 /* setup menu button */
2410                 sprintf(menustr, "Field Type%%t|None %%x0|Spherical %%x%d|Wind %%x%d|Vortex %%x%d|Curve Guide %%x%d", 
2411                                 PFIELD_FORCE, PFIELD_WIND, PFIELD_VORTEX, PFIELD_GUIDE);
2412                 
2413                 if(pd->forcefield==PFIELD_FORCE) tipstr= "Object center attracts or repels particles";
2414                 else if(pd->forcefield==PFIELD_WIND) tipstr= "Constant force applied in direction of Object Z axis";
2415                 else if(pd->forcefield==PFIELD_VORTEX) tipstr= "Particles swirl around Z-axis of the Object";
2416                 else if(pd->forcefield==PFIELD_GUIDE) tipstr= "Use a Curve Path to guide particles";
2417                 
2418                 uiDefButS(block, MENU, B_FIELD_DEP, menustr,                    10,160,140,20, &pd->forcefield, 0.0, 0.0, 0, 0, tipstr);
2419                 MEM_freeN(menustr);
2420                 
2421                 if(pd->forcefield) {
2422                         uiBlockBeginAlign(block);
2423                         if(pd->forcefield == PFIELD_GUIDE) {
2424                                 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.");
2425                                 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");
2426                         }
2427                         else {  
2428                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Strength: ",     10,110,140,20, &pd->f_strength, -1000, 1000, 10, 0, "Strength of force field");
2429                                 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)");
2430                         }
2431                         
2432                         uiBlockBeginAlign(block);
2433                         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");
2434                         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");
2435                         uiBlockEndAlign(block);
2436                         
2437                         if(pd->forcefield == PFIELD_GUIDE)
2438                                 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");
2439                         
2440                 }
2441                 
2442                 uiDefBut(block, LABEL, 0, "Deflection", 160,180,140,20, NULL, 0.0, 0, 0, 0, "");
2443                         
2444                 /* only meshes collide now */
2445                 if(ob->type==OB_MESH) {
2446                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision");
2447                         if(pd->deflect) {
2448                                 uiDefBut(block, LABEL, 0, "Particles",                  160,140,150,20, NULL, 0.0, 0, 0, 0, "");
2449                                 
2450                                 uiBlockBeginAlign(block);
2451                                 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");
2452                                 uiDefButF(block, NUM, B_DIFF, "Rnd Damping: ",  160,100,150,20, &pd->pdef_rdamp, 0.0, 1.0, 10, 0, "Random variation of damping");
2453                                 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");
2454                                 uiBlockEndAlign(block);
2455                                 
2456                                 uiDefBut(block, LABEL, 0, "Soft Body",                  160,60,150,20, NULL, 0.0, 0, 0, 0, "");
2457
2458                                 uiBlockBeginAlign(block);
2459                                 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");
2460                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,20,150,20, &pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2461                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160, 0,150,20, &pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2462                         }
2463                 }               
2464         }
2465 }
2466
2467
2468 /* Panel for softbodies */
2469 static void object_softbodies__enable(void *ob_v, void *arg2)
2470 {
2471         Object *ob = ob_v;
2472         ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody);
2473
2474         if (modifiers_isSoftbodyEnabled(ob)) {
2475                 if (md) {
2476                         md->mode &= ~(eModifierMode_Render|eModifierMode_Realtime);
2477                 }
2478         } else {
2479                 if (!md) {
2480                         md = modifier_new(eModifierType_Softbody);
2481                         BLI_addhead(&ob->modifiers, md);
2482                 }
2483
2484                 md->mode |= eModifierMode_Render|eModifierMode_Realtime;
2485
2486                 if (!ob->soft) {
2487                         ob->soft= sbNew();
2488                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2489                 }
2490         }
2491
2492         allqueue(REDRAWBUTSEDIT, 0);
2493 }
2494
2495 static void object_softbodies_II(Object *ob)
2496 {
2497         uiBlock *block;
2498         static int val;
2499
2500         block= uiNewBlock(&curarea->uiblocks, "object_softbodies_II", UI_EMBOSS, UI_HELV, curarea->win);
2501         uiNewPanelTabbed("Soft Body", "Physics");
2502         if(uiNewPanel(curarea, block, "Soft Body Collision", "Physics", 651, 0, 318, 204)==0) return;
2503
2504         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2505
2506         val = modifiers_isSoftbodyEnabled(ob);
2507         if(!val) {
2508                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2509                 uiBlockBeginAlign(block);
2510                 uiDefBut(block, LABEL, 0, "Object is not a softbody",10,190,300,20, NULL, 0.0, 0, 0, 0, ""); 
2511                 uiDefBut(block, LABEL, 0, "However it can deflect a softbody",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2512                 /* OTHER OBJECTS COLLISION STUFF */
2513                 if (ob->type==OB_MESH){
2514                         uiBlockBeginAlign(block);
2515                         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");
2516                         if(ob->pd->deflect) {
2517                                 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");
2518                             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");
2519                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2520                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2521                         }
2522                 }
2523                 uiBlockEndAlign(block);
2524         }
2525         else{
2526                 SoftBody *sb= ob->soft;
2527                 /* SELF COLLISION STUFF */
2528                 if ((ob->type==OB_MESH)||(ob->type==OB_CURVE) ) {
2529                         uiBlockBeginAlign(block);
2530                         if (ob->softflag & OB_SB_EDGES){
2531                                 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");
2532                                 if(ob->softflag & OB_SB_SELF){
2533                                         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");
2534                                         uiDefButS(block, ROW, B_DIFF, "Man",10,150,60,20, &sb->sbc_mode, 4.0,(float)0, 0, 0, "Manual adjust");
2535                                         uiDefButS(block, ROW, B_DIFF, "Av",70,150,60,20, &sb->sbc_mode, 4.0,(float)1, 0, 0, "Average Spring lenght * Ball Size");
2536                                         uiDefButS(block, ROW, B_DIFF, "Min",130,150,60,20, &sb->sbc_mode, 4.0,(float)2, 0, 0, "Minimal Spring lenght * Ball Size");
2537                                         uiDefButS(block, ROW, B_DIFF, "Max",190,150,60,20, &sb->sbc_mode, 4.0,(float)3, 0, 0, "Maximal Spring lenght * Ball Size");
2538                                         uiDefButS(block, ROW, B_DIFF, "AvMiMa",250,150,60,20, &sb->sbc_mode, 4.0,(float)4, 0, 0, "(Min+Max)/2 * Ball Size");
2539                                         uiDefButF(block, NUM, B_DIFF, "B Stiff:", 10,130,150,20, &sb->ballstiff, 0.001,  100.0, 10, 0, "Ball inflating presure");
2540                                         uiDefButF(block, NUM, B_DIFF, "B Damp:", 160,130,150,20, &sb->balldamp,  0.001,  1.0, 10, 0, "Blending to inelastic collision");
2541                                 }
2542                         }
2543                         else{
2544                                 uiDefBut(block, LABEL, 0, "<Self Collision> not available because there",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2545                                 uiDefBut(block, LABEL, 0, "are no edges, enable <Use Edges>",10,150,300,20, NULL, 0.0, 0, 0, 0, ""); 
2546                         }
2547
2548                         uiBlockEndAlign(block);
2549                         /*SOLVER SETTINGS*/
2550                         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");
2551                         uiDefButBitS(block, TOG, SBSO_OLDERR, B_DIFF,"O", 140,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Old Error Calculation");
2552                         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");
2553                         uiDefButBitS(block, TOG, SBSO_MONITOR, B_DIFF,"M", 290,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Turn on SB diagnose console prints");
2554                         uiDefButS(block, NUM, B_DIFF, "MinS:", 10,80,100,20, &sb->minloops,  0.00,  30000.0, 10, 0, "Minimal # solver steps/frame ");
2555                         uiDefButS(block, NUM, B_DIFF, "MaxS:", 110,80,100,20, &sb->maxloops,  0.00,  30000.0, 10, 0, "Maximal # solver steps/frame ");
2556                         uiDefButS(block, NUM, B_DIFF, "Choke:", 210,80,100,20, &sb->choke, 0.00,  100.0, 10, 0, "'Viscosity' inside collision target ");
2557                 }
2558                 /* OTHER OBJECTS COLLISION STUFF */
2559                 if (ob->type==OB_MESH){
2560                         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");
2561                         if(ob->pd->deflect) {
2562                                 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");
2563                             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");
2564                                 uiDefButF(block, NUM, B_DIFF, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2565                                 uiDefButF(block, NUM, B_DIFF, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2566                         }
2567                 }
2568                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2569         }
2570         uiBlockEndAlign(block);
2571 }
2572
2573 static void object_softbodies(Object *ob)
2574 {
2575         uiBlock *block;
2576         static int val;
2577         uiBut *but;
2578         block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
2579         if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
2580
2581         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2582
2583         val = modifiers_isSoftbodyEnabled(ob);
2584         but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Soft Body",      10,200,130,20, &val, 0, 0, 0, 0, "Sets object to become soft body");
2585         uiButSetFunc(but, object_softbodies__enable, ob, NULL);
2586         uiDefBut(block, LABEL, 0, "",10,10,300,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2587
2588         if(modifiers_isSoftbodyEnabled(ob)){
2589                 SoftBody *sb= ob->soft;
2590                 int defCount;
2591                 char *menustr;
2592
2593                 if(sb==NULL) {
2594                         sb= ob->soft= sbNew();
2595                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2596                 }
2597
2598                 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");
2599
2600                 if(sb->keys) uiSetButLock(1, "Soft Body is baked, free it first");
2601
2602                 if(ob->softflag & OB_SB_BAKESET) {
2603                         uiBlockBeginAlign(block);
2604                         uiDefButI(block, NUM, B_DIFF, "Start:",                 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking");
2605                         uiDefButI(block, NUM, B_DIFF, "End:",                   110, 170,100,20, &sb->efra, 1.0, 10000.0, 10, 0, "End frame for baking");
2606                         uiDefButI(block, NUM, B_DIFF, "Interval:",              210, 170,100,20, &sb->interval, 1.0, 10.0, 10, 0, "Interval in frames between baked keys");
2607                         uiBlockEndAlign(block);
2608
2609                         uiDefButS(block, TOG, B_DIFF, "Local",                  10, 145,100,20, &sb->local, 0.0, 0.0, 0, 0, "Use local coordinates for baking");
2610
2611
2612                         uiClearButLock();
2613                         uiBlockBeginAlign(block);
2614
2615                         if(sb->keys) {
2616                                 char str[128];
2617                                 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");
2618                                 sprintf(str, "Stored %d vertices %d keys %.3f MB", sb->totpoint, sb->totkey, ((float)16*sb->totpoint*sb->totkey)/(1024.0*1024.0));
2619                                 uiDefBut(block, LABEL, 0, str, 10, 100,300,20, NULL, 0.0, 0.0, 00, 0, "");
2620                         }
2621                         else                            
2622                                 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");
2623
2624                 }
2625                 else {
2626                         /* GENERAL STUFF */
2627                         static char str[128];
2628                         if (sb->totpoint){
2629                         sprintf(str, "Vertex Mass; Object mass %f [k]",sb->nodemass*sb->totpoint/1000.0f);
2630                         }
2631                         else{
2632                         sprintf(str, "Vertex Mass");
2633                         }
2634                         uiBlockBeginAlign(block);
2635                         uiDefButF(block, NUM, B_DIFF, "Friction:", 10, 170,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements");
2636                         uiDefButF(block, NUM, B_DIFF, "Mass:",     160, 170,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str);
2637                         uiDefButF(block, NUM, B_DIFF, "Grav:",     10,150,150,20, &sb->grav , 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
2638                         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");
2639                         uiBlockEndAlign(block);
2640
2641                         /* GOAL STUFF */
2642                         uiBlockBeginAlign(block);
2643                         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");
2644                         if (ob->softflag & OB_SB_GOAL){
2645                                 if(ob->type==OB_MESH) {
2646                                         menustr= get_vertexgroup_menustr(ob);
2647                                         defCount=BLI_countlist(&ob->defbase);
2648                                         if(defCount==0) sb->vertgroup= 0;
2649                                         uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr,      140,120,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
2650                                         MEM_freeN (menustr);
2651
2652                                         if(sb->vertgroup) {
2653                                                 bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
2654                                                 if(defGroup)
2655                                                         uiDefBut(block, BUT, B_DIFF, defGroup->name,    160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group");
2656                                                 else
2657                                                         uiDefBut(block, BUT, B_DIFF, "(no group)",      160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
2658                                                 uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,120,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
2659                                         }
2660                                         else
2661                                                 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");
2662                                 }
2663                                 else {
2664                                         uiDefButS(block, TOG, B_SOFTBODY_CHANGE, "W",                   140,120,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
2665                                         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");
2666                                 }
2667
2668                                 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");
2669                                 uiDefButF(block, NUM, B_DIFF, "G Damp:",        160,100,150,20, &sb->goalfrict  , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
2670                                 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");
2671                                 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");
2672                         }
2673                         uiBlockEndAlign(block);
2674
2675                         /* EDGE SPRING STUFF */
2676                         if(ob->type!=OB_SURF) {
2677                                 uiBlockBeginAlign(block);
2678                                 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");
2679                         if (ob->softflag & OB_SB_EDGES){
2680                                 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");
2681                                 uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_DIFF, "CEdge",               220,50,45,20, &ob->softflag, 0, 0, 0, 0, "Edge collide too"); 
2682                                 uiDefButBitS(block, TOG, OB_SB_FACECOLL, B_DIFF, "CFace",               265,50,45,20, &ob->softflag, 0, 0, 0, 0, "Faces collide too SLOOOOOW warning "); 
2683                                 uiDefButF(block, NUM, B_DIFF, "E Stiff:",       10,30,150,20, &sb->inspring, 0.0,  0.999, 10, 0, "Edge spring stiffness");
2684                                 uiDefButF(block, NUM, B_DIFF, "E Damp:",        160,30,150,20, &sb->infrict, 0.0,  50.0, 10, 0, "Edge spring friction");
2685                                 uiDefButS(block, NUM, B_DIFF, "Aero:",     10,10,150,20, &sb->aeroedge,  0.00,  30000.0, 10, 0, "Make edges 'sail'");
2686                                 if(ob->type==OB_MESH) {
2687                                         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");
2688                                 }
2689                                 else sb->secondspring = 0;
2690                                 uiDefBut(block, LABEL, 0, "",10,10,1,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2691                         }
2692                                 uiBlockEndAlign(block);
2693                         }
2694                 }
2695         }
2696         uiBlockEndAlign(block);
2697 }
2698
2699 static void object_panel_particles_motion(Object *ob)
2700 {
2701         uiBlock *block;
2702         uiBut *but;
2703         PartEff *paf= give_parteff(ob);
2704
2705         if (paf==NULL) return;
2706                 
2707         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles_motion", UI_EMBOSS, UI_HELV, curarea->win);
2708         uiNewPanelTabbed("Particles ", "Physics");
2709         if(uiNewPanel(curarea, block, "Particle Motion", "Physics", 320, 0, 318, 204)==0) return;
2710         
2711         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2712         
2713         /* top row */
2714         uiBlockBeginAlign(block);
2715         uiDefButI(block, NUM, B_CALCEFFECT, "Keys:",    0,180,75,20, &paf->totkey, 1.0, 100.0, 0, 0, "Specify the number of key positions");
2716         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");
2717         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");
2718         uiDefButF(block, NUM, B_CALCEFFECT, "RLife:",   225,180,85,20, &paf->randlife, 0.0, 2.0, 10, 1, "Give the particlelife a random variation");
2719         uiBlockEndAlign(block);
2720         
2721         /* left collumn */
2722         uiDefBut(block, LABEL, 0, "Velocity:",                  0,160,150,20, NULL, 0.0, 0, 0, 0, "");
2723         uiBlockBeginAlign(block);
2724         uiBlockSetCol(block, TH_BUT_SETTING2);
2725         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");
2726         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");
2727         uiDefButF(block, NUM, B_CALCEFFECT, "Random:",          0,104,150,18, &paf->randfac, 0.0, 2.0, 1, 3, "Give the startingspeed a random variation");
2728         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");
2729         uiDefButF(block, NUM, B_CALCEFFECT, "Damping:",         0,68,150,18, &paf->damp, 0.0, 1.0, 1, 3, "Specify the damping factor");
2730         uiBlockSetCol(block, TH_AUTO);
2731         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");
2732         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)OBACT);
2733         uiBlockEndAlign(block);
2734         
2735         uiDefBut(block, LABEL, 0, "Texture Emission",                   0,30,150,20, NULL, 0.0, 0, 0, 0, "");
2736         uiBlockBeginAlign(block);
2737         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");
2738         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");
2739         
2740         /* right collumn */
2741         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_CALCEFFECT, "GR:", 160, 155, 150, 20, &paf->group, "Limit Force Fields to this Group"); 
2742
2743         uiBlockBeginAlign(block);
2744         uiDefBut(block, LABEL, 0, "Force:",                             160,130,75,20, NULL, 0.0, 0, 0, 0, "");
2745         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");
2746         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");
2747         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");
2748         
2749         uiBlockBeginAlign(block);
2750         uiDefButS(block, NUM, B_CALCEFFECT, "Tex:",             160,80,75,20, &paf->speedtex, 1.0, 10.0, 0, 2, "Specify the texture used for force");
2751         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");
2752         uiDefButF(block, NUM, B_CALCEFFECT, "Y:",               160,60,75,20, paf->defvec+1,-1.0, 1.0, 1, 2, "Specify the Y axis of a force, determined by the texture");