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