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