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