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