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