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