8281ce7bc8f563475175f0ea8169282788b5884f
[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_image.h"
123 #include "BKE_ipo.h"
124 #include "BKE_lattice.h"
125 #include "BKE_material.h"
126 #include "BKE_mball.h"
127 #include "BKE_mesh.h"
128 #include "BKE_modifier.h"
129 #include "BKE_object.h"
130 #include "BKE_sound.h"
131 #include "BKE_texture.h"
132 #include "BKE_utildefines.h"
133 #include "BKE_DerivedMesh.h"
134
135 #include "LBM_fluidsim.h"
136
137 #include "BIF_editconstraint.h"
138 #include "BIF_editdeform.h"
139
140 #include "BSE_editipo.h"
141 #include "BSE_edit.h"
142
143 #include "BDR_editobject.h"
144
145 #include "butspace.h" // own module
146
147 static float prspeed=0.0;
148 float prlen=0.0;
149
150
151 /* ********************* CONSTRAINT ***************************** */
152
153 static void constraint_active_func(void *ob_v, void *con_v)
154 {
155         Object *ob= ob_v;
156         bConstraint *con;
157         ListBase *lb;
158         
159         /* lets be nice and escape if its active already */
160         if(con_v) {
161                 con= con_v;
162                 if(con->flag & CONSTRAINT_ACTIVE) return;
163         }
164         
165         lb= get_active_constraints(ob);
166         
167         for(con= lb->first; con; con= con->next) {
168                 if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
169                 else con->flag &= ~CONSTRAINT_ACTIVE;
170         }
171
172         /* make sure ipowin and buttons shows it */
173         if(ob->ipowin==ID_CO) {
174                 allqueue(REDRAWIPO, ID_CO);
175                 allspace(REMAKEIPO, 0);
176                 allqueue(REDRAWNLA, 0);
177         }
178         allqueue(REDRAWBUTSOBJECT, 0);
179 }
180
181 static void add_constraint_to_active(Object *ob, bConstraint *con)
182 {
183         ListBase *list;
184         
185         list = get_active_constraints(ob);
186         if (list) {
187                 unique_constraint_name(con, list);
188                 BLI_addtail(list, con);
189                 
190                 con->flag |= CONSTRAINT_ACTIVE;
191                 for(con= con->prev; con; con= con->prev)
192                         con->flag &= ~CONSTRAINT_ACTIVE;
193         }
194 }
195
196 /* returns base ID for Ipo, sets actname to channel if appropriate */
197 /* should not make action... */
198 static void get_constraint_ipo_context(Object *ob, char *actname)
199 {
200         
201         /* todo; check object if it has ob-level action ipo */
202         
203         if (ob->flag & OB_POSEMODE) {
204                 bPoseChannel *pchan;
205                 
206                 pchan = get_active_posechannel(ob);
207                 if (pchan) {
208                         BLI_strncpy(actname, pchan->name, 32);
209                 }
210         }
211         else if(ob->ipoflag & OB_ACTION_OB)
212                 strcpy(actname, "Object");
213 }       
214
215 /* initialize UI to show Ipo window and make sure channels etc exist */
216 static void enable_constraint_ipo_func (void *ob_v, void *con_v)
217 {
218         Object *ob= ob_v;
219         bConstraint *con = con_v;
220         char actname[32]="";
221         
222         /* verifies if active constraint is set and shown in UI */
223         constraint_active_func(ob_v, con_v);
224         
225         /* the context */
226         get_constraint_ipo_context(ob, actname);
227         
228         /* adds ipo & channels & curve if needed */
229         verify_ipo((ID *)ob, ID_CO, actname, con->name);
230         
231         /* make sure ipowin shows it */
232         ob->ipowin= ID_CO;
233         allqueue(REDRAWIPO, ID_CO);
234         allspace(REMAKEIPO, 0);
235         allqueue(REDRAWNLA, 0);
236 }
237
238
239 static void add_influence_key_to_constraint_func (void *ob_v, void *con_v)
240 {
241         Object *ob= ob_v;
242         bConstraint *con = con_v;
243         IpoCurve *icu;
244         char actname[32]="";
245         
246         /* verifies if active constraint is set and shown in UI */
247         constraint_active_func(ob_v, con_v);
248         
249         /* the context */
250         get_constraint_ipo_context(ob, actname);
251
252         /* adds ipo & channels & curve if needed */
253         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
254
255         insert_vert_ipo(icu, CFRA, con->enforce);
256         
257         /* make sure ipowin shows it */
258         ob->ipowin= ID_CO;
259         allqueue(REDRAWIPO, ID_CO);
260         allspace(REMAKEIPO, 0);
261         allqueue(REDRAWNLA, 0);
262         
263         BIF_undo_push("Insert Influence Key");
264 }
265
266
267 static void del_constraint_func (void *ob_v, void *con_v)
268 {
269         bConstraint *con= con_v;
270         bConstraintChannel *chan;
271         ListBase *lb;
272         
273         /* remove ipo channel */
274         lb= get_active_constraint_channels(ob_v, 0);
275         if(lb) {
276                 chan = get_constraint_channel(lb, con->name);
277                 if(chan) {
278                         if(chan->ipo) chan->ipo->id.us--;
279                         BLI_freelinkN(lb, chan);
280                 }
281         }
282         /* remove constraint itself */
283         lb= get_active_constraints(ob_v);
284         free_constraint_data (con);
285         BLI_freelinkN(lb, con);
286         
287         constraint_active_func(ob_v, NULL);
288
289         BIF_undo_push("Delete constraint");
290         allqueue(REDRAWBUTSOBJECT, 0);
291         allqueue(REDRAWIPO, 0); 
292
293 }
294
295 static void verify_constraint_name_func (void *ob_v, void *con_v)
296 {
297         ListBase *conlist;
298         bConstraint *con= con_v;
299         
300         if (!con)
301                 return;
302         
303         conlist = get_active_constraints(ob_v);
304         unique_constraint_name (con, conlist);
305         constraint_active_func(ob_v, con);
306
307 }
308
309 static void get_constraint_typestring (char *str, bConstraint *con)
310 {
311         switch (con->type){
312         case CONSTRAINT_TYPE_CHILDOF:
313                 strcpy (str, "Child Of");
314                 return;
315         case CONSTRAINT_TYPE_NULL:
316                 strcpy (str, "Null");
317                 return;
318         case CONSTRAINT_TYPE_TRACKTO:
319                 strcpy (str, "Track To");
320                 return;
321         case CONSTRAINT_TYPE_MINMAX:
322                 strcpy (str, "Floor");
323                 return;
324         case CONSTRAINT_TYPE_KINEMATIC:
325                 strcpy (str, "IK Solver");
326                 return;
327         case CONSTRAINT_TYPE_ROTLIKE:
328                 strcpy (str, "Copy Rotation");
329                 return;
330         case CONSTRAINT_TYPE_LOCLIKE:
331                 strcpy (str, "Copy Location");
332                 return;
333         case CONSTRAINT_TYPE_ACTION:
334                 strcpy (str, "Action");
335                 return;
336         case CONSTRAINT_TYPE_LOCKTRACK:
337                 strcpy (str, "Locked Track");
338                 return;
339         case CONSTRAINT_TYPE_FOLLOWPATH:
340                 strcpy (str, "Follow Path");
341                 return;
342         case CONSTRAINT_TYPE_STRETCHTO:
343                 strcpy (str, "Stretch To");
344                 return;
345         default:
346                 strcpy (str, "Unknown");
347                 return;
348         }
349 }
350
351 static int get_constraint_col(bConstraint *con)
352 {
353         switch (con->type) {
354         case CONSTRAINT_TYPE_NULL:
355                 return TH_BUT_NEUTRAL;
356         case CONSTRAINT_TYPE_KINEMATIC:
357                 return TH_BUT_SETTING2;
358         case CONSTRAINT_TYPE_TRACKTO:
359                 return TH_BUT_SETTING;
360         case CONSTRAINT_TYPE_ROTLIKE:
361                 return TH_BUT_SETTING1;
362         case CONSTRAINT_TYPE_LOCLIKE:
363                 return TH_BUT_POPUP;
364         case CONSTRAINT_TYPE_MINMAX:
365                 return TH_BUT_POPUP;
366         case CONSTRAINT_TYPE_ACTION:
367                 return TH_BUT_ACTION;
368         case CONSTRAINT_TYPE_LOCKTRACK:
369                 return TH_BUT_SETTING;
370         case CONSTRAINT_TYPE_FOLLOWPATH:
371                 return TH_BUT_SETTING2;
372         case CONSTRAINT_TYPE_STRETCHTO:
373                 return TH_BUT_SETTING;
374         default:
375                 return TH_REDALERT;
376         }
377 }
378
379 static void constraint_moveUp(void *ob_v, void *con_v)
380 {
381         bConstraint *con, *constr= con_v;
382         ListBase *conlist;
383         
384         if(constr->prev) {
385                 conlist = get_active_constraints(ob_v);
386                 for(con= conlist->first; con; con= con->next) {
387                         if(con==constr) {
388                                 BLI_remlink(conlist, con);
389                                 BLI_insertlink(conlist, con->prev->prev, con);
390                                 break;
391                         }
392                 }
393         }
394         BIF_undo_push("Move constraint");
395 }
396
397 static void constraint_moveDown(void *ob_v, void *con_v)
398 {
399         bConstraint *con, *constr= con_v;
400         ListBase *conlist;
401         
402         if(constr->next) {
403                 conlist = get_active_constraints(ob_v);
404                 for(con= conlist->first; con; con= con->next) {
405                         if(con==constr) {
406                                 BLI_remlink(conlist, con);
407                                 BLI_insertlink(conlist, con->next, con);
408                                 break;
409                         }
410                 }
411         }
412         BIF_undo_push("Move constraint");
413 }
414
415 /* autocomplete callback for ID buttons */
416 void autocomplete_bone(char *str, void *arg_v)
417 {
418         Object *ob= (Object *)arg_v;
419         char truncate[40]= {0};
420         
421         if(ob==NULL || ob->pose==NULL) return;
422         
423         /* search if str matches the beginning of an ID struct */
424         if(str[0]) {
425                 bPoseChannel *pchan;
426                 
427                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
428                         int a;
429                         
430                         for(a=0; a<31; a++) {
431                                 if(str[a]==0 || str[a]!=pchan->name[a])
432                                         break;
433                         }
434                         /* found a match */
435                         if(str[a]==0) {
436                                 /* first match */
437                                 if(truncate[0]==0)
438                                         BLI_strncpy(truncate, pchan->name, 32);
439                                 else {
440                                         /* remove from truncate what is not in bone->name */
441                                         for(a=0; a<31; a++) {
442                                                 if(truncate[a]!=pchan->name[a])
443                                                         truncate[a]= 0;
444                                         }
445                                 }
446                         }
447                 }
448                 if(truncate[0])
449                         BLI_strncpy(str, truncate, 32);
450         }
451 }
452
453 /* autocomplete callback for ID buttons */
454 void autocomplete_vgroup(char *str, void *arg_v)
455 {
456         Object *ob= (Object *)arg_v;
457         char truncate[40]= {0};
458         
459         if(ob==NULL) return;
460         
461         /* search if str matches the beginning of an ID struct */
462         if(str[0]) {
463                 bDeformGroup *dg;
464                 
465                 for(dg= ob->defbase.first; dg; dg= dg->next) {
466                         int a;
467                         
468                         for(a=0; a<31; a++) {
469                                 if(str[a]==0 || str[a]!=dg->name[a])
470                                         break;
471                         }
472                         /* found a match */
473                         if(str[a]==0) {
474                                 /* first match */
475                                 if(truncate[0]==0)
476                                         BLI_strncpy(truncate, dg->name, 32);
477                                 else {
478                                         /* remove from truncate what is not in bone->name */
479                                         for(a=0; a<31; a++) {
480                                                 if(truncate[a]!=dg->name[a])
481                                                         truncate[a]= 0;
482                                         }
483                                 }
484                         }
485                 }
486                 if(truncate[0])
487                         BLI_strncpy(str, truncate, 32);
488         }
489 }
490
491 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
492 {
493         Object *ob= OBACT;
494         uiBut *but;
495         char typestr[64];
496         short height, width = 265;
497         int curCol, rb_col;
498
499         /* unless button has own callback, it adds this callback to button */
500         uiBlockSetFunc(block, constraint_active_func, ob, con);
501         
502         get_constraint_typestring (typestr, con);
503
504         curCol = get_constraint_col(con);
505
506         /* Draw constraint header */
507         uiBlockSetEmboss(block, UI_EMBOSSN);
508         
509         /* rounded header */
510         rb_col= (con->flag & CONSTRAINT_ACTIVE)?40:20;
511         uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-1, width+40, 22, NULL, 5.0, 0.0, 
512                          (con->flag & CONSTRAINT_EXPAND)?3:15 , rb_col-20, ""); 
513         
514         /* open/close */
515         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");
516         
517         /* up down */
518         uiBlockSetEmboss(block, UI_EMBOSS);
519         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");
520         uiButSetFunc(but, constraint_moveUp, ob, con);
521         
522         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");
523         uiButSetFunc(but, constraint_moveDown, ob, con);
524         
525         if (con->flag & CONSTRAINT_EXPAND) {
526                 
527                 if (con->flag & CONSTRAINT_DISABLE) {
528                         BIF_ThemeColor(TH_REDALERT);
529                         uiBlockSetCol(block, TH_REDALERT);
530                 }
531                 else
532                         BIF_ThemeColor(curCol);
533
534                 /*if (type==TARGET_BONE)
535                         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"); 
536                 else
537                         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"); 
538                 */
539                 uiBlockSetEmboss(block, UI_EMBOSS);
540                 
541                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
542                 
543                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
544                 uiButSetFunc(but, verify_constraint_name_func, ob, con);
545         }       
546         else{
547                 uiBlockSetEmboss(block, UI_EMBOSSN);
548
549                 if (con->flag & CONSTRAINT_DISABLE) {
550                         uiBlockSetCol(block, TH_REDALERT);
551                         BIF_ThemeColor(TH_REDALERT);
552                 }
553                 else
554                         BIF_ThemeColor(curCol);
555                 
556                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
557                 
558                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
559         }
560
561         uiBlockSetCol(block, TH_AUTO);  
562         
563         uiBlockSetEmboss(block, UI_EMBOSSN);
564         
565         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");
566         uiButSetFunc(but, del_constraint_func, ob, con);
567
568         uiBlockSetEmboss(block, UI_EMBOSS);
569
570
571         /* Draw constraint data*/
572         if (!(con->flag & CONSTRAINT_EXPAND)) {
573                 (*yco)-=21;
574         }
575         else {
576                 switch (con->type){
577                 case CONSTRAINT_TYPE_ACTION:
578                         {
579                                 bActionConstraint *data = con->data;
580                                 bArmature *arm;
581
582                                 height = 88;
583                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
584                                 
585                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
586
587                                 /* Draw target parameters */
588                                 uiBlockBeginAlign(block);
589                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
590
591                                 arm = get_armature(data->tar);
592                                 if (arm){
593                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
594                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
595                                 }
596                                 else
597                                         strcpy (data->subtarget, "");
598                                 uiBlockEndAlign(block);
599
600                                 /* Draw action button */
601                                 uiBlockBeginAlign(block);
602                                 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");
603                                 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"); 
604                                 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");
605
606                                 uiBlockBeginAlign(block);
607                                 uiDefButS(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"); 
608                                 uiDefButS(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"); 
609                                 
610                                 uiBlockBeginAlign(block);
611                                 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");
612                                 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");
613                                 uiBlockEndAlign(block);
614                         }
615                         break;
616                 case CONSTRAINT_TYPE_LOCLIKE:
617                         {
618                                 bLocateLikeConstraint *data = con->data;
619                                 bArmature *arm;
620                                 
621                                 height = 66;
622                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
623
624                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
625
626                                 /* Draw target parameters */
627                                 uiBlockBeginAlign(block);
628                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
629
630                                 arm = get_armature(data->tar);
631                                 if (arm){
632                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
633                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
634                                 }
635                                 else
636                                         strcpy (data->subtarget, "");
637                                 uiBlockEndAlign(block);
638                                 
639                                 /* Draw XYZ toggles */
640                                 uiBlockBeginAlign(block);
641                                 if (arm)
642                                         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");
643                                 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");
644                                 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");
645                                 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");
646                                 uiBlockEndAlign(block);
647                         }
648                         break;
649                 case CONSTRAINT_TYPE_ROTLIKE:
650                         {
651                                 bRotateLikeConstraint *data = con->data;
652                                 bArmature *arm;
653                                 
654                                 /* also old files stuff... version patch is too much code! */
655                                 if(data->flag==0) data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
656                                 
657                                 height = 66;
658                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
659                                 
660                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
661
662                                 /* Draw target parameters */
663                                 uiBlockBeginAlign(block);
664                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
665
666                                 arm = get_armature(data->tar);
667                                 if (arm){
668                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
669                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
670                                 }
671                                 else
672                                         strcpy (data->subtarget, "");
673                                 uiBlockEndAlign(block);
674                                 
675                                 /* Draw XYZ toggles */
676                                 uiBlockBeginAlign(block);
677                                 if (arm)
678                                         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");
679                                 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");
680                                 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");
681                                 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");
682                                 uiBlockEndAlign(block);
683                         }
684                         break;
685                 case CONSTRAINT_TYPE_KINEMATIC:
686                         {
687                                 bKinematicConstraint *data = con->data;
688                                 bArmature *arm;
689                                 
690                                 height = 108;
691                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
692                                 
693                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
694
695                                 /* Draw target parameters */
696                                 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");
697                                 
698                                 uiBlockBeginAlign(block);
699                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 19, &data->tar, "Target Object"); 
700
701                                 arm = get_armature(data->tar);
702                                 if (arm) {
703                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,19, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
704                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
705                                 }
706                                 else
707                                         strcpy (data->subtarget, "");
708         
709                                 uiBlockBeginAlign(block);
710                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_TIP, B_CONSTRAINT_TEST, "Use Tip", *xco, *yco-64, 142, 19, &data->flag, 0, 0, 0, 0, "Include Bone's tip als last element in Chain");
711                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "ChainLen:", *xco+142, *yco-64,143,19, &data->rootbone, 0, 255, 0, 0, "If not zero, the amount of bones in this chain");
712                                 
713                                 uiBlockBeginAlign(block);
714                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "PosW ", *xco, *yco-86, 142, 19, &data->weight, 0.01, 1.0, 2, 2, "For Tree-IK: weight of position control for this target");
715                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "RotW ", *xco+142, *yco-86, 143, 19, &data->orientweight, 0.01, 1.0, 2, 2, "For Tree-IK: Weight of orientation control for this target");
716                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Tolerance:", *xco, *yco-106, 142, 19, &data->tolerance, 0.0001f, 1.0, 0, 0, "Maximum distance to target after solving"); 
717                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "Iterations:", *xco+142, *yco-106, 143, 19, &data->iterations, 1, 10000, 0, 0, "Maximum number of solving iterations"); 
718                                 
719                         }
720                         break;
721                 case CONSTRAINT_TYPE_TRACKTO:
722                         {
723                                 bTrackToConstraint *data = con->data;
724                                 bArmature *arm;
725
726                                 height = 66;
727                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
728                                 
729                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
730
731                                 /* Draw target parameters */
732                                 uiBlockBeginAlign(block);
733                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
734
735                                 arm = get_armature(data->tar);
736                                 if (arm){
737                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
738                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
739                                 }
740                                 else
741                                         strcpy (data->subtarget, "");
742                                 uiBlockEndAlign(block);
743
744                                 uiBlockBeginAlign(block);
745                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
746                                 
747                                 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");
748                                 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");
749                                 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");
750                                 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");
751                                 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");
752                                 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");
753                                 uiBlockEndAlign(block);
754                                 
755                                 uiBlockBeginAlign(block);
756                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
757                                 
758                                 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");
759                                 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");
760                                 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");
761                                 uiBlockEndAlign(block);
762                         }
763                         break;
764                 case CONSTRAINT_TYPE_MINMAX:
765                         {
766                                 bMinMaxConstraint *data = con->data;
767                                 bArmature *arm;
768
769                                 height = 66;
770                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
771                                 
772                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
773
774                                 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"); 
775
776                                 /* Draw target parameters */
777                                 uiBlockBeginAlign(block);
778                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
779
780                                 arm = get_armature(data->tar);
781                                 if (arm){
782                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
783                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
784                                 }
785                                 else
786                                         strcpy (data->subtarget, "");
787                                 uiBlockEndAlign(block);
788
789                                 but=uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 54, 18, &data->sticky, 0, 24, 0, 0, "Immobilize object while constrained");
790                                 
791                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
792
793                                 uiBlockBeginAlign(block);                       
794                                 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");
795                                 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");
796                                 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");
797                                 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");
798                                 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");
799                                 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");
800                                 uiBlockEndAlign(block);
801                         }
802                         break;
803                 case CONSTRAINT_TYPE_LOCKTRACK:
804                         {
805                                 bLockTrackConstraint *data = con->data;
806                                 bArmature *arm;
807                                 height = 66;
808                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
809
810                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
811
812                                 /* Draw target parameters */
813                                 uiBlockBeginAlign(block);
814                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
815
816                                 arm = get_armature(data->tar);
817                                 if (arm){
818                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
819                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
820                                 }
821                                 else
822                                         strcpy (data->subtarget, "");
823                                 uiBlockEndAlign(block);
824                                 
825                                 uiBlockBeginAlign(block);
826                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
827                                 
828                                 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");
829                                 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");
830                                 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");
831                                 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");
832                                 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");
833                                 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");
834                                 uiBlockEndAlign(block);
835                                 
836                                 uiBlockBeginAlign(block);
837                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
838                                 
839                                 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");
840                                 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");
841                                 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");
842                                 uiBlockEndAlign(block);
843                         }
844                         break;
845                 case CONSTRAINT_TYPE_FOLLOWPATH:
846                         {
847                                 bFollowPathConstraint *data = con->data;
848
849                                 height = 66;
850                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
851                                 
852                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
853
854                                 /* Draw target parameters */
855                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
856                                 
857                                 /* Draw Curve Follow toggle */
858                                 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");
859
860                                 /* Draw Offset number button */
861                                 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"); 
862
863                                 uiBlockBeginAlign(block);
864                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
865                                 
866                                 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");
867                                 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");
868                                 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");
869                                 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");
870                                 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");
871                                 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");
872                                 uiBlockEndAlign(block);
873                                 
874                                 uiBlockBeginAlign(block);
875                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
876                                 
877                                 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");
878                                 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");
879                                 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");
880                                 uiBlockEndAlign(block);
881                         }
882                         break;
883                 case CONSTRAINT_TYPE_STRETCHTO:
884                         {
885                                 bStretchToConstraint *data = con->data;
886                                 bArmature *arm;
887                                 
888                                 height = 105;
889                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
890                                 
891                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
892
893
894                                 /* Draw target parameters */
895                                 uiBlockBeginAlign(block);
896                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
897
898                                 arm = get_armature(data->tar);
899                                 if (arm){
900                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
901                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
902                                 }
903                                 else
904                                         strcpy (data->subtarget, "");
905                                 uiBlockEndAlign(block);
906
907                                 
908                                 uiBlockBeginAlign(block);
909                                 uiDefButF(block,BUTM,B_CONSTRAINT_TEST,"R",*xco, *yco-60,20,18,&(data->orglength),0.0,0,0,0,"Recalculate RLenght");
910                                 uiDefButF(block,NUM,B_CONSTRAINT_TEST,"Rest Length:",*xco+18, *yco-60,237,18,&(data->orglength),0.0,100,0.5,0.5,"Lenght at Rest Position");
911                                 uiBlockEndAlign(block);
912
913                                 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");
914
915                                 uiBlockBeginAlign(block);
916                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Vol:",*xco+14, *yco-104,30,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
917                                 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");
918                                 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");
919                                 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");
920                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"NONE", *xco+114, *yco-104,50,18, &data->volmode, 12.0, 3.0, 0, 0, "Ignore Volume");
921                                 uiBlockEndAlign(block);
922
923                                 
924                                 uiBlockBeginAlign(block);
925                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Plane:",*xco+175, *yco-104,40,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
926                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",       *xco+215, *yco-104,20,18, &data->plane, 12.0, 0.0, 0, 0, "Keep X axis");
927                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",       *xco+235, *yco-104,20,18, &data->plane, 12.0, 2.0, 0, 0, "Keep Z axis");
928                                 uiBlockEndAlign(block);
929                                 }
930                         break;
931                 case CONSTRAINT_TYPE_NULL:
932                         {
933                                 height = 17;
934                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
935                                 
936                         }
937                         break;
938                 default:
939                         height = 0;
940                         break;
941                 }
942
943                 (*yco)-=(24+height);
944         }
945
946         if (con->type!=CONSTRAINT_TYPE_NULL) {
947                 uiBlockBeginAlign(block);
948                 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");
949                 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");
950                 /* If this is on an object or bone, add ipo channel the constraint */
951                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
952                 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");
953                 /* Add a keyframe to the influence IPO */
954                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
955                 uiBlockEndAlign(block);
956                 (*yco)-=24;
957         } else {
958                 (*yco)-=3;
959         }
960         
961 }
962
963 static uiBlock *add_constraintmenu(void *arg_unused)
964 {
965         Object *ob= OBACT;
966         uiBlock *block;
967         ListBase *conlist;
968         short yco= 0;
969         
970         conlist = get_active_constraints(ob);
971         
972         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
973
974         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE,"Copy Location",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
975         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE,"Copy Rotation",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
976         
977         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
978         
979         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO,"Track To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
980         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX,"Floor",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
981         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK,"Locked Track",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
982         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH,"Follow Path",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
983         
984         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
985         
986         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO,"Stretch To",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
987
988         if (ob->flag & OB_POSEMODE) {
989                 uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
990                 
991                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC,"IK Solver",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
992                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION,"Action",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
993                 
994         }
995         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
996
997         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL,"Null",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
998         
999         uiTextBoundsBlock(block, 50);
1000         uiBlockSetDirection(block, UI_DOWN);
1001                 
1002         return block;
1003 }
1004
1005 void do_constraintbuts(unsigned short event)
1006 {
1007         Object *ob= OBACT;
1008         
1009         switch(event) {
1010         case B_CONSTRAINT_TEST:
1011                 break;  // no handling
1012         case B_CONSTRAINT_INF:
1013                 /* influence; do not execute actions for 1 dag_flush */
1014                 if(ob->pose)
1015                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1016
1017         case B_CONSTRAINT_CHANGETARGET:
1018                 if(ob->pose) ob->pose->flag |= POSE_RECALC;     // checks & sorts pose channels
1019                 DAG_scene_sort(G.scene);
1020                 break;
1021                 
1022         case B_CONSTRAINT_ADD_NULL:
1023                 {
1024                         bConstraint *con;
1025                         
1026                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1027                         add_constraint_to_active(ob, con);
1028
1029                         BIF_undo_push("Add constraint");
1030                 }
1031                 break;
1032         case B_CONSTRAINT_ADD_KINEMATIC:
1033                 {
1034                         bConstraint *con;
1035                         
1036                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1037                         add_constraint_to_active(ob, con);
1038
1039                         BIF_undo_push("Add constraint");
1040                 }
1041                 break;
1042         case B_CONSTRAINT_ADD_TRACKTO:
1043                 {
1044                         bConstraint *con;
1045
1046                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1047                         add_constraint_to_active(ob, con);
1048
1049                         BIF_undo_push("Add constraint");
1050                 }
1051                 break;
1052         case B_CONSTRAINT_ADD_MINMAX:
1053                 {
1054                         bConstraint *con;
1055
1056                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1057                         add_constraint_to_active(ob, con);
1058
1059                         BIF_undo_push("Add constraint");
1060                 }
1061                 break;
1062         case B_CONSTRAINT_ADD_ROTLIKE:
1063                 {
1064                         bConstraint *con;
1065
1066                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1067                         add_constraint_to_active(ob, con);
1068
1069                         BIF_undo_push("Add constraint");
1070                 }
1071                 break;
1072         case B_CONSTRAINT_ADD_LOCLIKE:
1073                 {
1074                         bConstraint *con;
1075
1076                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1077                         add_constraint_to_active(ob, con);
1078
1079                         BIF_undo_push("Add constraint");
1080                 }
1081                 break;
1082         case B_CONSTRAINT_ADD_ACTION:
1083                 {
1084                         bConstraint *con;
1085
1086                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1087                         add_constraint_to_active(ob, con);
1088
1089                         BIF_undo_push("Add constraint");
1090                 }
1091                 break;
1092         case B_CONSTRAINT_ADD_LOCKTRACK:
1093                 {
1094                         bConstraint *con;
1095
1096                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1097                         add_constraint_to_active(ob, con);
1098
1099                         BIF_undo_push("Add constraint");
1100                 }
1101                 break;
1102         case B_CONSTRAINT_ADD_FOLLOWPATH:
1103                 {
1104                         bConstraint *con;
1105
1106                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1107                         add_constraint_to_active(ob, con);
1108
1109                 }
1110                 break;
1111         case B_CONSTRAINT_ADD_STRETCHTO:
1112                 {
1113                         bConstraint *con;
1114                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1115                         add_constraint_to_active(ob, con);
1116                                 
1117                         BIF_undo_push("Add constraint");
1118                 }
1119                 break;
1120
1121         default:
1122                 break;
1123         }
1124
1125         object_test_constraints(ob);
1126         
1127         if(ob->pose) update_pose_constraint_flags(ob->pose);
1128         
1129         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1130         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1131         
1132         allqueue (REDRAWVIEW3D, 0);
1133         allqueue (REDRAWBUTSOBJECT, 0);
1134 }
1135
1136 void object_panel_constraint(char *context)
1137 {
1138         uiBlock *block;
1139         Object *ob= OBACT;
1140         ListBase *conlist;
1141         bConstraint *curcon;
1142         short xco, yco;
1143         char str[64];
1144         
1145         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
1146         if(uiNewPanel(curarea, block, "Constraints", context, 640, 0, 318, 204)==0) return;
1147
1148         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1149         /* so first we make it default height */
1150         uiNewPanelHeight(block, 204);
1151
1152         if(G.obedit==OBACT) return;     // ??
1153         
1154         conlist = get_active_constraints(OBACT);
1155         
1156         if (conlist) {
1157                  
1158                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint", 0, 190, 130, 20, "Add a new constraint");
1159                 
1160                 /* print active object or bone */
1161                 str[0]= 0;
1162                 if (ob->flag & OB_POSEMODE){
1163                         bPoseChannel *pchan= get_active_posechannel(ob);
1164                         if(pchan) sprintf(str, "To Bone: %s", pchan->name);
1165                 }
1166                 else {
1167                         sprintf(str, "To Object: %s", ob->id.name+2);
1168                 }
1169                 uiDefBut(block, LABEL, 1, str,  150, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Displays Active Object or Bone name");
1170                 
1171                 /* Go through the list of constraints and draw them */
1172                 xco = 10;
1173                 yco = 160;
1174                 
1175                 for (curcon = conlist->first; curcon; curcon=curcon->next) {
1176                         /* hrms, the temporal constraint should not draw! */
1177                         if(curcon->type==CONSTRAINT_TYPE_KINEMATIC) {
1178                                 bKinematicConstraint *data= curcon->data;
1179                                         if(data->flag & CONSTRAINT_IK_TEMP)
1180                                                 continue;
1181                         }
1182                         /* Draw default constraint header */
1183                         draw_constraint(block, conlist, curcon, &xco, &yco);    
1184                 }
1185                 
1186                 if(yco < 0) uiNewPanelHeight(block, 204-yco);
1187                 
1188         }
1189 }
1190
1191 static void object_panel_draw(Object *ob)
1192 {
1193         uiBlock *block;
1194         int xco, a, dx, dy;
1195         
1196         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
1197         if(uiNewPanel(curarea, block, "Draw", "Object", 320, 0, 318, 204)==0) return;
1198
1199         /* LAYERS */
1200         xco= 120;
1201         dx= 35;
1202         dy= 30;
1203
1204         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
1205         
1206         uiBlockBeginAlign(block);
1207         for(a=0; a<5; a++)
1208                 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, "");
1209         for(a=0; a<5; a++)
1210                 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, "");
1211                 
1212         xco+= 7;
1213         uiBlockBeginAlign(block);
1214         for(a=5; a<10; a++)
1215                 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, "");
1216         for(a=5; a<10; a++)
1217                 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, "");
1218
1219         uiBlockEndAlign(block);
1220
1221         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
1222         
1223         uiBlockBeginAlign(block);
1224         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
1225         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
1226         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
1227         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
1228         uiBlockEndAlign(block);
1229         
1230         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
1231         
1232         uiBlockBeginAlign(block);
1233         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
1234         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
1235         
1236         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
1237                                                                                                                                         120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
1238         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");
1239         
1240         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
1241         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");
1242         
1243         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)");
1244         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");
1245
1246 }
1247
1248 static void softbody_bake(Object *ob)
1249 {
1250         SoftBody *sb= ob->soft;
1251         ScrArea *sa;
1252         float frameleno= G.scene->r.framelen;
1253         int cfrao= CFRA;
1254         unsigned short event=0;
1255         short val;
1256         
1257         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
1258         CFRA= sb->sfra;
1259         update_for_newframe_muted();    // put everything on this frame
1260         sbObjectToSoftbody(ob); // put softbody in restposition
1261         ob->softflag |= OB_SB_BAKEDO;
1262         
1263         curarea->win_swap= 0;           // clean swapbuffers
1264         
1265         for(; CFRA <= sb->efra; CFRA++) {
1266                 set_timecursor(CFRA);
1267                 
1268                 update_for_newframe_muted();
1269                 
1270                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
1271                         if(sa->spacetype == SPACE_VIEW3D) {
1272                                 scrarea_do_windraw(sa);
1273                         }
1274                 }
1275                 screen_swapbuffers();
1276                 
1277                 while(qtest()) {
1278                         
1279                         event= extern_qread(&val);
1280                         if(event==ESCKEY) break;
1281                 }
1282                 if(event==ESCKEY) break;
1283         }
1284         
1285         if(event==ESCKEY) sbObjectToSoftbody(ob);       // clears all
1286         
1287         /* restore */
1288         waitcursor(0);
1289         ob->softflag &= ~OB_SB_BAKEDO;
1290         CFRA= cfrao;
1291         G.scene->r.framelen= frameleno;
1292         update_for_newframe_muted();
1293         allqueue(REDRAWVIEW3D, 0);
1294         allqueue(REDRAWBUTSOBJECT, 0);
1295 }
1296
1297
1298 // NT store processed path & file prefix for fluidsim bake directory
1299 void fluidsimFilesel(char *selection)
1300 {
1301         Object *ob = OBACT;
1302         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
1303         char prefix[FILE_MAXFILE];
1304         char *srch, *srchSub, *srchExt, *lastFound;
1305         int isElbeemSurf = 0;
1306
1307         // check cfg?
1308         // make prefix
1309         strcpy(srcDir, selection);
1310         BLI_splitdirstring(srcDir, srcFile);
1311         strcpy(prefix, srcFile);
1312         // check if this is a previously generated surface mesh file
1313         srch = strstr(prefix, "fluidsurface_");
1314         // TODO search from back...
1315         if(srch) {
1316                 srchSub = strstr(prefix,"_preview_");
1317                 if(!srchSub) srchSub = strstr(prefix,"_final_");
1318                 srchExt = strstr(prefix,".gz.bobj");
1319                 if(!srchExt) srchExt = strstr(prefix,".bobj");
1320                 if(srchSub && srchExt) {
1321                         *srch = '\0';
1322                         isElbeemSurf = 1;
1323                 }
1324         }
1325         if(!isElbeemSurf) {
1326                 // try to remove suffix
1327                 lastFound = NULL;
1328                 srch = strchr(prefix, '.'); // search last . from extension
1329                 while(srch) {
1330                         lastFound = srch;
1331                         if(srch) {
1332                                 srch++;
1333                                 srch = strchr(srch, '.');
1334                         }
1335                 }
1336                 if(lastFound) {
1337                         *lastFound = '\0';
1338                 } 
1339         }
1340
1341         if(ob->fluidsimSettings) {
1342                 //strcpy(ob->fluidsimSettings->surfdataPath, selection);
1343                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
1344                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
1345                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
1346
1347                 // redraw view & buttons...
1348                 allqueue(REDRAWBUTSOBJECT, 0);
1349                 allqueue(REDRAWVIEW3D, 0);
1350                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1351         }
1352 }
1353
1354 void do_object_panels(unsigned short event)
1355 {
1356         Object *ob;
1357         Effect *eff;
1358         
1359         ob= OBACT;
1360
1361         switch(event) {
1362         case B_TRACKBUTS:
1363                 ob= OBACT;
1364                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1365                 allqueue(REDRAWVIEW3D, 0);
1366                 break;
1367         case B_RECALCPATH:
1368                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1369                 allqueue(REDRAWVIEW3D, 0);
1370                 break;
1371         case B_PRINTSPEED:
1372                 ob= OBACT;
1373                 if(ob) {
1374                         float vec[3];
1375                         CFRA++;
1376                         do_ob_ipo(ob);
1377                         where_is_object(ob);
1378                         VECCOPY(vec, ob->obmat[3]);
1379                         CFRA--;
1380                         do_ob_ipo(ob);
1381                         where_is_object(ob);
1382                         VecSubf(vec, vec, ob->obmat[3]);
1383                         prspeed= Normalise(vec);
1384                         scrarea_queue_winredraw(curarea);
1385                 }
1386                 break;
1387         case B_PRINTLEN:
1388                 ob= OBACT;
1389                 if(ob && ob->type==OB_CURVE) {
1390                         Curve *cu=ob->data;
1391                         
1392                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
1393                         scrarea_queue_winredraw(curarea);
1394                 } 
1395                 break;
1396         case B_RELKEY:
1397                 allspace(REMAKEIPO, 0);
1398                 allqueue(REDRAWBUTSOBJECT, 0);
1399                 allqueue(REDRAWIPO, 0);
1400                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1401                 break;
1402         case B_CURVECHECK:
1403                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1404                 allqueue(REDRAWVIEW3D, 0);
1405                 break;
1406         
1407         case B_SOFTBODY_CHANGE:
1408                 ob= OBACT;
1409                 if(ob) {
1410                         ob->softflag |= OB_SB_REDO;
1411                         allqueue(REDRAWBUTSOBJECT, 0);
1412                         allqueue(REDRAWVIEW3D, 0);
1413                 }
1414                 break;
1415         case B_SOFTBODY_DEL_VG:
1416                 ob= OBACT;
1417                 if(ob && ob->soft) {
1418                         ob->soft->vertgroup= 0;
1419                         ob->softflag |= OB_SB_REDO;
1420                         allqueue(REDRAWBUTSOBJECT, 0);
1421                         allqueue(REDRAWVIEW3D, 0);
1422                 }
1423                 break;
1424         case B_SOFTBODY_BAKE:
1425                 ob= OBACT;
1426                 if(ob && ob->soft) softbody_bake(ob);
1427                 break;
1428         case B_SOFTBODY_BAKE_FREE:
1429                 ob= OBACT;
1430                 if(ob && ob->soft) sbObjectToSoftbody(ob);
1431                 allqueue(REDRAWBUTSOBJECT, 0);
1432                 allqueue(REDRAWVIEW3D, 0);
1433                 break;
1434
1435         case B_FLUIDSIM_BAKE:
1436                 ob= OBACT;
1437                 /* write config files (currently no simulation) */
1438                 fluidsimBake(ob);
1439                 break;
1440         case B_FLUIDSIM_SELDIR: {
1441                         ScrArea *sa = closest_bigger_area();
1442                         ob= OBACT;
1443                         /* choose dir for surface files */
1444                         areawinset(sa->win);
1445                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
1446                 }
1447                 break;
1448         case B_FLUIDSIM_FORCEREDRAW:
1449                 /* force redraw */
1450                 allqueue(REDRAWBUTSOBJECT, 0);
1451                 allqueue(REDRAWVIEW3D, 0);
1452                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1453                 break;
1454                 
1455         default:
1456                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1457                         ob= OBACT;
1458                         if(ob) {
1459                                 int a=B_SELEFFECT;
1460                                 
1461                                 eff= ob->effect.first;
1462                                 while(eff) {
1463                                         if(event==a) eff->flag |= SELECT;
1464                                         else eff->flag &= ~SELECT;
1465                                         
1466                                         a++;
1467                                         eff= eff->next;
1468                                 }
1469                                 allqueue(REDRAWBUTSOBJECT, 0);
1470                         }
1471                 }
1472         }
1473
1474 }
1475
1476 static void object_panel_anim(Object *ob)
1477 {
1478         uiBlock *block;
1479         char str[32];
1480         
1481         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1482         if(uiNewPanel(curarea, block, "Anim settings", "Object", 0, 0, 318, 204)==0) return;
1483         
1484         uiBlockBeginAlign(block);
1485         uiDefButS(block, ROW,B_TRACKBUTS,"TrackX",      24,190,59,19, &ob->trackflag, 12.0, 0.0, 0, 0, "Specify the axis that points to another object");
1486         uiDefButS(block, ROW,B_TRACKBUTS,"Y",           85,190,19,19, &ob->trackflag, 12.0, 1.0, 0, 0, "Specify the axis that points to another object");
1487         uiDefButS(block, ROW,B_TRACKBUTS,"Z",           104,190,19,19, &ob->trackflag, 12.0, 2.0, 0, 0, "Specify the axis that points to another object");
1488         uiDefButS(block, ROW,B_TRACKBUTS,"-X",          124,190,24,19, &ob->trackflag, 12.0, 3.0, 0, 0, "Specify the axis that points to another object");
1489         uiDefButS(block, ROW,B_TRACKBUTS,"-Y",          150,190,24,19, &ob->trackflag, 12.0, 4.0, 0, 0, "Specify the axis that points to another object");
1490         uiDefButS(block, ROW,B_TRACKBUTS,"-Z",          178,190,24,19, &ob->trackflag, 12.0, 5.0, 0, 0, "Specify the axis that points to another object");
1491         uiBlockBeginAlign(block);
1492         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,190,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
1493         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,190,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
1494         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,190,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
1495         uiBlockBeginAlign(block);
1496         uiDefButBitS(block, TOG, OB_DRAWKEY, REDRAWVIEW3D, "Draw Key",          24,160,71,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
1497         uiDefButBitS(block, TOG, OB_DRAWKEYSEL, REDRAWVIEW3D, "Draw Key Sel",   97,160,81,19, &ob->ipoflag, 0, 0, 0, 0, "Limit the drawing of object keys");
1498         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,160,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
1499         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,160,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
1500         uiBlockBeginAlign(block);
1501         uiDefButBitS(block, TOG, OB_DUPLIFRAMES, REDRAWVIEW3D, "DupliFrames",   24,128,89,19, &ob->transflag, 0, 0, 0, 0, "Make copy of object for every frame");
1502         uiDefButBitS(block, TOG, OB_DUPLIVERTS, REDRAWVIEW3D, "DupliVerts",             114,128,82,19, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all vertices");
1503         uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",              200,128,31,19, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to facenormal");
1504         uiDefButBitS(block, TOG, OB_DUPLINOSPEED, REDRAWVIEW3D, "No Speed",     234,128,82,19, &ob->transflag, 0, 0, 0, 0, "Set dupliframes to still, regardless of frame");
1505         uiBlockBeginAlign(block);
1506         uiDefButS(block, NUM, REDRAWVIEW3D, "DupSta:",          24,105,141,19, &ob->dupsta, 1.0, (MAXFRAMEF - 1.0f), 0, 0, "Specify startframe for Dupliframes");
1507         uiDefButS(block, NUM, REDRAWVIEW3D, "DupOn:",           170,105,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "");
1508         uiDefButS(block, NUM, REDRAWVIEW3D, "DupEnd",           24,82,140,19, &ob->dupend, 1.0, MAXFRAMEF, 0, 0, "Specify endframe for Dupliframes");
1509         uiDefButS(block, NUM, REDRAWVIEW3D, "DupOff",           171,82,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "");
1510         uiBlockBeginAlign(block);
1511         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,51,56,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on its own objectipo");
1512         uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "Offs Par",                 82,51,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
1513         uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "Offs Particle",          140,51,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
1514         
1515         uiBlockBeginAlign(block);
1516         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,17,115,30, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
1517         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,17,104,31, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
1518         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,17,67,31, 0, 0, 0, 0, 0, "Print objectspeed");
1519         uiBlockEndAlign(block);
1520         
1521         sprintf(str, "%.4f", prspeed);
1522         uiDefBut(block, LABEL, 0, str,                                                  247,40,63,31, NULL, 1.0, 0, 0, 0, "");
1523         
1524 }
1525
1526 void do_effects_panels(unsigned short event)
1527 {
1528         Object *ob;
1529         Base *base;
1530         Effect *eff, *effn;
1531         PartEff *paf;
1532         
1533         ob= OBACT;
1534
1535         switch(event) {
1536
1537     case B_AUTOTIMEOFS:
1538                 auto_timeoffs();
1539                 break;
1540         case B_FRAMEMAP:
1541                 G.scene->r.framelen= G.scene->r.framapto;
1542                 G.scene->r.framelen/= G.scene->r.images;
1543                 allqueue(REDRAWALL, 0);
1544                 break;
1545         case B_NEWEFFECT:
1546                 if(ob) {
1547                         if (BLI_countlist(&ob->effect)==MAX_EFFECT)
1548                                 error("Unable to add: effect limit reached");
1549                         else
1550                                 copy_act_effect(ob);
1551                 }
1552                 DAG_scene_sort(G.scene);
1553                 BIF_undo_push("New effect");
1554                 allqueue(REDRAWBUTSOBJECT, 0);
1555                 break;
1556         case B_DELEFFECT:
1557                 if(ob==NULL || ob->type!=OB_MESH) break;
1558                 eff= ob->effect.first;
1559                 while(eff) {
1560                         effn= eff->next;
1561                         if(eff->flag & SELECT) {
1562                                 BLI_remlink(&ob->effect, eff);
1563                                 free_effect(eff);
1564                                 break;
1565                         }
1566                         eff= effn;
1567                 }
1568                 BIF_undo_push("Delete effect");
1569                 allqueue(REDRAWVIEW3D, 0);
1570                 allqueue(REDRAWBUTSOBJECT, 0);
1571                 break;
1572         case B_NEXTEFFECT:
1573                 if(ob==0 || ob->type!=OB_MESH) break;
1574                 eff= ob->effect.first;
1575                 while(eff) {
1576                         if(eff->flag & SELECT) {
1577                                 if(eff->next) {
1578                                         eff->flag &= ~SELECT;
1579                                         eff->next->flag |= SELECT;
1580                                 }
1581                                 break;
1582                         }
1583                         eff= eff->next;
1584                 }
1585                 allqueue(REDRAWBUTSOBJECT, 0);
1586                 break;
1587         case B_PREVEFFECT:
1588                 if(ob==0 || ob->type!=OB_MESH) break;
1589                 eff= ob->effect.first;
1590                 while(eff) {
1591                         if(eff->flag & SELECT) {
1592                                 if(eff->prev) {
1593                                         eff->flag &= ~SELECT;
1594                                         eff->prev->flag |= SELECT;
1595                                 }
1596                                 break;
1597                         }
1598                         eff= eff->next;
1599                 }
1600                 allqueue(REDRAWBUTSOBJECT, 0);
1601                 break;
1602         case B_EFFECT_DEP:
1603                 DAG_scene_sort(G.scene);
1604                 /* no break, pass on */
1605         case B_CALCEFFECT:
1606                 if(ob==NULL || ob->type!=OB_MESH) break;
1607                 eff= ob->effect.first;
1608                 while(eff) {
1609                         if(eff->flag & SELECT) {
1610                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
1611                         }
1612                         eff= eff->next;
1613                 }
1614                 allqueue(REDRAWVIEW3D, 0);
1615                 allqueue(REDRAWBUTSOBJECT, 0);
1616                 break;
1617         case B_PAF_SET_VG:
1618                 
1619                 paf= give_parteff(ob);
1620                 if(paf) {
1621                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname);
1622                         if(dg)
1623                                 paf->vertgroup= get_defgroup_num(ob, dg)+1;
1624                         else
1625                                 paf->vertgroup= 0;
1626                         
1627                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1628                         allqueue(REDRAWVIEW3D, 0);
1629                 }
1630                 break;
1631         case B_PAF_SET_VG1:
1632                 
1633                 paf= give_parteff(ob);
1634                 if(paf) {
1635                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname_v);
1636                         if(dg)
1637                                 paf->vertgroup_v= get_defgroup_num(ob, dg)+1;
1638                         else
1639                                 paf->vertgroup_v= 0;
1640                         
1641                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1642                         allqueue(REDRAWVIEW3D, 0);
1643                 }
1644                 break;
1645         case B_FIELD_DEP:
1646                 DAG_scene_sort(G.scene);
1647                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1648                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE) {
1649                         Curve *cu= ob->data;
1650                         
1651                         cu->flag |= (CU_PATH|CU_3D);
1652                         do_curvebuts(B_CU3D);   /* all curves too */
1653                         
1654                         DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1655                 }
1656                 allqueue(REDRAWVIEW3D, 0);
1657                 allqueue(REDRAWBUTSOBJECT, 0);
1658                 break;
1659         case B_FIELD_CHANGE:
1660                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1661                 allqueue(REDRAWVIEW3D, 0);
1662                 break;
1663         case B_RECALCAL:
1664                 base= FIRSTBASE;
1665                 while(base) {
1666                         if(base->lay & G.vd->lay) {
1667                                 ob= base->object;
1668                                 eff= ob->effect.first;
1669                                 while(eff) {
1670                                         if(eff->flag & SELECT) {
1671                                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
1672                                         }
1673                                         eff= eff->next;
1674                                 }
1675                         }
1676                         base= base->next;
1677                 }
1678                 allqueue(REDRAWVIEW3D, 0);
1679                 break;
1680         default:
1681                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1682                         ob= OBACT;
1683                         if(ob) {
1684                                 int a=B_SELEFFECT;
1685                                 
1686                                 eff= ob->effect.first;
1687                                 while(eff) {
1688                                         if(event==a) eff->flag |= SELECT;
1689                                         else eff->flag &= ~SELECT;
1690                                         
1691                                         a++;
1692                                         eff= eff->next;
1693                                 }
1694                                 allqueue(REDRAWBUTSOBJECT, 0);
1695                         }
1696                 }
1697         }
1698
1699 }
1700
1701 /* Panel for particle interaction settings */
1702 static void object_panel_fields(Object *ob)
1703 {
1704         uiBlock *block;
1705
1706         block= uiNewBlock(&curarea->uiblocks, "object_panel_fields", UI_EMBOSS, UI_HELV, curarea->win);
1707         if(uiNewPanel(curarea, block, "Fields and Deflection", "Physics", 0, 0, 318, 204)==0) return;
1708
1709         /* should become button, option? */
1710         if(ob->pd==NULL) {
1711                 ob->pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
1712                 /* and if needed, init here */
1713                 ob->pd->pdef_sbdamp = 0.1f;
1714                 ob->pd->pdef_sbift  = 0.2f;
1715                 ob->pd->pdef_sboft  = 0.02f;
1716         }
1717         
1718         if(ob->pd) {
1719                 PartDeflect *pd= ob->pd;
1720                 char *menustr= MEM_mallocN(256, "temp string");
1721                 char *tipstr="Choose field type";
1722                 
1723                 uiDefBut(block, LABEL, 0, "Fields",             10,180,140,20, NULL, 0.0, 0, 0, 0, "");
1724                 
1725                 /* setup menu button */
1726                 sprintf(menustr, "Field Type%%t|None %%x0|Spherical %%x%d|Wind %%x%d|Vortex %%x%d|Curve Guide %%x%d", 
1727                                 PFIELD_FORCE, PFIELD_WIND, PFIELD_VORTEX, PFIELD_GUIDE);
1728                 
1729                 if(pd->forcefield==PFIELD_FORCE) tipstr= "Object center attracts or repels particles";
1730                 else if(pd->forcefield==PFIELD_WIND) tipstr= "Constant force applied in direction of Object Z axis";
1731                 else if(pd->forcefield==PFIELD_VORTEX) tipstr= "Particles swirl around Z-axis of the Object";
1732                 else if(pd->forcefield==PFIELD_GUIDE) tipstr= "Use a Curve Path to guide particles";
1733                 
1734                 uiDefButS(block, MENU, B_FIELD_DEP, menustr,                    10,160,140,20, &pd->forcefield, 0.0, 0.0, 0, 0, tipstr);
1735                 MEM_freeN(menustr);
1736                 
1737                 if(pd->forcefield) {
1738                         uiBlockBeginAlign(block);
1739                         if(pd->forcefield == PFIELD_GUIDE) {
1740                                 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.");
1741                                 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");
1742                         }
1743                         else {  
1744                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Strength: ",     10,110,140,20, &pd->f_strength, -1000, 1000, 10, 0, "Strength of force field");
1745                                 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)");
1746                         }
1747                         
1748                         uiBlockBeginAlign(block);
1749                         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");
1750                         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");
1751                         uiBlockEndAlign(block);
1752                         
1753                         if(pd->forcefield == PFIELD_GUIDE)
1754                                 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");
1755                         
1756                 }
1757                 
1758                 uiDefBut(block, LABEL, 0, "Deflection", 160,180,140,20, NULL, 0.0, 0, 0, 0, "");
1759                         
1760                 /* only meshes collide now */
1761                 if(ob->type==OB_MESH) {
1762                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision");
1763                         if(pd->deflect) {
1764                                 uiDefBut(block, LABEL, 0, "Particles",                  160,140,150,20, NULL, 0.0, 0, 0, 0, "");
1765                                 
1766                                 uiBlockBeginAlign(block);
1767                                 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");
1768                                 uiDefButF(block, NUM, B_DIFF, "Rnd Damping: ",  160,100,150,20, &pd->pdef_rdamp, 0.0, 1.0, 10, 0, "Random variation of damping");
1769                                 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");
1770                                 uiBlockEndAlign(block);
1771                                 
1772                                 uiDefBut(block, LABEL, 0, "Soft Body",                  160,60,150,20, NULL, 0.0, 0, 0, 0, "");
1773
1774                                 uiBlockBeginAlign(block);
1775                                 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");
1776                                 uiDefButF(block, NUM, B_DIFF, "Inner:", 160,20,150,20, &pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
1777                                 uiDefButF(block, NUM, B_DIFF, "Outer:", 160, 0,150,20, &pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
1778                         }
1779                 }               
1780         }
1781 }
1782
1783
1784 /* Panel for softbodies */
1785 static void object_softbodies__enable(void *ob_v, void *arg2)
1786 {
1787         Object *ob = ob_v;
1788         ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody);
1789
1790         if (modifiers_isSoftbodyEnabled(ob)) {
1791                 if (md) {
1792                         md->mode &= ~(eModifierMode_Render|eModifierMode_Realtime);
1793                 }
1794         } else {
1795                 if (!md) {
1796                         md = modifier_new(eModifierType_Softbody);
1797                         BLI_addhead(&ob->modifiers, md);
1798                 }
1799
1800                 md->mode |= eModifierMode_Render|eModifierMode_Realtime;
1801
1802                 if (!ob->soft) {
1803                         ob->soft= sbNew();
1804                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
1805                 }
1806         }
1807
1808         allqueue(REDRAWBUTSEDIT, 0);
1809 }
1810
1811 static void object_softbodies(Object *ob)
1812 {
1813         uiBlock *block;
1814         
1815         block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
1816         if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
1817
1818         /* do not allow to combine with force fields */
1819         /* if(ob->pd && ob->pd->deflect) { */
1820         /* no reason for that any more BM */
1821         if(0) {
1822                 uiDefBut(block, LABEL, 0, "Object has Deflection,",             10,160,300,20, NULL, 0.0, 0, 0, 0, "");
1823                 uiDefBut(block, LABEL, 0, "no Soft Body possible",              10,140,300,20, NULL, 0.0, 0, 0, 0, "");
1824         } else {
1825                 static int val;
1826                 uiBut *but;
1827
1828                 val = modifiers_isSoftbodyEnabled(ob);
1829                 but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Enable Soft Body",       10,200,150,20, &val, 0, 0, 0, 0, "Sets object to become soft body");
1830                 uiButSetFunc(but, object_softbodies__enable, ob, NULL);
1831                 uiDefBut(block, LABEL, 0, "",   160, 200,150,20, NULL, 0.0, 0.0, 0, 0, "");     // alignment reason
1832         }
1833         
1834         if(modifiers_isSoftbodyEnabled(ob)) {
1835                 SoftBody *sb= ob->soft;
1836                 int defCount;
1837                 char *menustr;
1838                 
1839                 if(sb==NULL) {
1840                         sb= ob->soft= sbNew();
1841                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
1842                 }
1843                 
1844                 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");
1845                 
1846                 if(sb->keys) uiSetButLock(1, "Soft Body is baked, free it first");
1847                 
1848                 if(ob->softflag & OB_SB_BAKESET) {
1849                         uiBlockBeginAlign(block);
1850                         uiDefButS(block, NUM, B_DIFF, "Start:",                 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking");
1851                         uiDefButS(block, NUM, B_DIFF, "End:",                   110, 170,100,20, &sb->efra, 1.0, 10000.0, 10, 0, "End frame for baking");
1852                         uiDefButS(block, NUM, B_DIFF, "Interval:",              210, 170,100,20, &sb->interval, 1.0, 10.0, 10, 0, "Interval in frames between baked keys");
1853                         
1854                         uiClearButLock();
1855                         
1856                         uiBlockBeginAlign(block);
1857                         if(sb->keys) {
1858                                 char str[128];
1859                                 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");
1860                                 sprintf(str, "Stored %d vertices %d keys %.3f MB", sb->totpoint, sb->totkey, ((float)16*sb->totpoint*sb->totkey)/(1024.0*1024.0));
1861                                 uiDefBut(block, LABEL, 0, str, 10, 100,300,20, NULL, 0.0, 0.0, 00, 0, "");
1862                         }
1863                         else                            
1864                                 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");
1865                 }
1866                 else {
1867                         /* GENERAL STUFF */
1868                         uiBlockBeginAlign(block);
1869                         uiDefButF(block, NUM, B_DIFF, "Friction:",              10, 170,150,20, &sb->mediafrict, 0.0, 10.0, 10, 0, "General media friction for point movements");
1870                         uiDefButF(block, NUM, B_DIFF, "Mass:",                  160, 170,150,20, &sb->nodemass , 0.001, 50.0, 10, 0, "Point Mass, the heavier the slower");
1871                         uiDefButF(block, NUM, B_DIFF, "Grav:",                  10,150,150,20, &sb->grav , 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
1872                         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");
1873                         uiDefButF(block, NUM, B_DIFF, "Error Limit:",   10,130,150,20, &sb->rklimit , 0.01, 1.0, 10, 0, "The Runge-Kutta ODE solver error limit, low value gives more precision");
1874                         uiBlockEndAlign(block);
1875                         
1876                         /* GOAL STUFF */
1877                         uiBlockBeginAlign(block);
1878                         uiDefButBitS(block, TOG, OB_SB_GOAL, B_SOFTBODY_CHANGE, "Use Goal",     10,100,130,20, &ob->softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
1879                         
1880                         if(ob->type==OB_MESH) {
1881                                 menustr= get_vertexgroup_menustr(ob);
1882                                 defCount=BLI_countlist(&ob->defbase);
1883                                 if(defCount==0) sb->vertgroup= 0;
1884                                 uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr,      140,100,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
1885                                 MEM_freeN (menustr);
1886
1887                                 if(sb->vertgroup) {
1888                                         bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
1889                                         if(defGroup)
1890                                                 uiDefBut(block, BUT, B_DIFF, defGroup->name,    160,100,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group");
1891                                         else
1892                                                 uiDefBut(block, BUT, B_DIFF, "(no group)",      160,100,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
1893                                         uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,100,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
1894                                 }
1895                                 else
1896                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,100,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
1897                         }
1898                         else {
1899                                 uiDefButS(block, TOG, B_SOFTBODY_CHANGE, "W",                   140,100,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
1900                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,100,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
1901                         }
1902
1903                         uiDefButF(block, NUM, B_DIFF, "G Stiff:",       10,80,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
1904                         uiDefButF(block, NUM, B_DIFF, "G Damp:",        160,80,150,20, &sb->goalfrict  , 0.0, 10.0, 10, 0, "Goal (vertex target position) friction");
1905                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Min:",              10,60,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
1906                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Max:",              160,60,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
1907                         uiBlockEndAlign(block);
1908                         
1909                         /* EDGE SPRING STUFF */
1910                         if(ob->type!=OB_SURF) {
1911                                 uiBlockBeginAlign(block);
1912                                 uiDefButBitS(block, TOG, OB_SB_EDGES, B_SOFTBODY_CHANGE, "Use Edges",           10,30,150,20, &ob->softflag, 0, 0, 0, 0, "Use Edges as springs");
1913                                 uiDefButBitS(block, TOG, OB_SB_QUADS, B_SOFTBODY_CHANGE, "Stiff Quads",         160,30,150,20, &ob->softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
1914                                 uiDefButF(block, NUM, B_DIFF, "E Stiff:",       10,10,150,20, &sb->inspring, 0.0,  0.999, 10, 0, "Edge spring stiffness");
1915                                 uiDefButF(block, NUM, B_DIFF, "E Damp:",        160,10,150,20, &sb->infrict, 0.0,  10.0, 10, 0, "Edge spring friction");
1916                                 uiBlockEndAlign(block);
1917                         }
1918                 }
1919         }
1920         uiBlockEndAlign(block);
1921
1922 }
1923
1924 static void object_panel_particles_motion(Object *ob)
1925 {
1926         uiBlock *block;
1927         uiBut *but;
1928         PartEff *paf= give_parteff(ob);
1929
1930         if (paf==NULL) return;
1931                 
1932         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles_motion", UI_EMBOSS, UI_HELV, curarea->win);
1933         uiNewPanelTabbed("Particles ", "Physics");
1934         if(uiNewPanel(curarea, block, "Particle Motion", "Physics", 320, 0, 318, 204)==0) return;
1935         
1936         /* top row */
1937         uiBlockBeginAlign(block);
1938         uiDefButI(block, NUM, B_CALCEFFECT, "Keys:",    0,180,75,20, &paf->totkey, 1.0, 100.0, 0, 0, "Specify the number of key positions");
1939         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");
1940         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");
1941         uiDefButF(block, NUM, B_CALCEFFECT, "RLife:",   225,180,85,20, &paf->randlife, 0.0, 2.0, 10, 1, "Give the particlelife a random variation");
1942         uiBlockEndAlign(block);
1943         
1944         /* left collumn */
1945         uiDefBut(block, LABEL, 0, "Velocity:",                  0,160,150,20, NULL, 0.0, 0, 0, 0, "");
1946         uiBlockBeginAlign(block);
1947         uiBlockSetCol(block, TH_BUT_SETTING2);
1948         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");
1949         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");
1950         uiDefButF(block, NUM, B_CALCEFFECT, "Random:",          0,104,150,18, &paf->randfac, 0.0, 2.0, 1, 3, "Give the startingspeed a random variation");
1951         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");
1952         uiDefButF(block, NUM, B_CALCEFFECT, "Damping:",         0,68,150,18, &paf->damp, 0.0, 1.0, 1, 3, "Specify the damping factor");
1953         uiBlockSetCol(block, TH_AUTO);
1954         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");
1955         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)OBACT);
1956         uiBlockEndAlign(block);
1957         
1958         uiDefBut(block, LABEL, 0, "Texture Emission",                   0,30,150,20, NULL, 0.0, 0, 0, 0, "");
1959         uiBlockBeginAlign(block);
1960         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");
1961         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");
1962         
1963         /* right collumn */
1964         uiBlockBeginAlign(block);
1965         uiDefBut(block, LABEL, 0, "Force:",                             160,130,75,20, NULL, 0.0, 0, 0, 0, "");
1966         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");
1967         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");
1968         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");
1969         
1970         uiBlockBeginAlign(block);
1971         uiDefButS(block, NUM, B_CALCEFFECT, "Tex:",             160,80,75,20, &paf->speedtex, 1.0, 10.0, 0, 2, "Specify the texture used for force");
1972         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");
1973         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");
1974         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");
1975         
1976         uiBlockBeginAlign(block);
1977         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");
1978         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");
1979         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");
1980         
1981         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");
1982         
1983 }
1984
1985
1986 static void object_panel_particles(Object *ob)
1987 {
1988         uiBlock *block;
1989         uiBut *but;
1990         PartEff *paf= give_parteff(ob);
1991         
1992         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles", UI_EMBOSS, UI_HELV, curarea->win);
1993         if(uiNewPanel(curarea, block, "Particles ", "Physics", 320, 0, 318, 204)==0) return;
1994
1995         if (ob->type == OB_MESH) {
1996                 uiBlockBeginAlign(block);
1997                 if(paf==NULL)
1998                         uiDefBut(block, BUT, B_NEWEFFECT, "NEW",        0,180,75,20, 0, 0, 0, 0, 0, "Create a new Particle effect");
1999                 else
2000                         uiDefBut(block, BUT, B_DELEFFECT, "Delete", 0,180,75,20, 0, 0, 0, 0, 0, "Delete the effect");
2001         }
2002         else uiDefBut(block, LABEL, 0, "Only Mesh Objects can generate particles",                              10,180,300,20, NULL, 0.0, 0, 0, 0, "");
2003         
2004         
2005         if(paf==NULL) return;
2006         
2007         uiDefBut(block, BUT, B_RECALCAL, "RecalcAll",           75,180,75,20, 0, 0, 0, 0, 0, "Update all particle systems");
2008         uiBlockEndAlign(block);
2009         
2010         uiDefBut(block, LABEL, 0, "Emit:",                                      0,150,75,20, NULL, 0.0, 0, 0, 0, "");
2011         uiBlockBeginAlign(block);
2012         uiDefButI(block, NUM, B_CALCEFFECT, "Amount:",          0,130,150,20, &paf->totpart, 1.0, 100000.0, 0, 0, "The total number of particles");
2013         if(paf->flag & PAF_STATIC) {
2014                 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");
2015         }
2016         else {
2017                 uiDefButF(block, NUM, B_CALCEFFECT, "Sta:",             0,110,75,20, &paf->sta, -250.0, MAXFRAMEF, 100, 1, "Frame # to start emitting particles");
2018                 uiDefButF(block, NUM, B_CALCEFFECT, "End:",             75,110,75,20, &paf->end, 1.0, MAXFRAMEF, 100, 1, "Frame # to stop emitting particles");
2019         }
2020         uiDefButF(block, NUM, B_CALCEFFECT, "Life:",            0,90,75,20, &paf->lifetime, 1.0, MAXFRAMEF, 100, 1, "Specify the life span of the particles");
2021         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");
2022         uiBlockEndAlign(block);
2023         
2024         uiDefBut(block, LABEL, 0, "From:",                                      0,70,75,20, NULL, 0.0, 0, 0, 0, "");
2025         uiBlockBeginAlign(block);
2026         uiDefButBitS(block, TOGN, PAF_OFACE, B_CALCEFFECT, "Verts",     0,50,75,20, &paf->flag, 0, 0, 0, 0, "Emit particles from vertices");
2027         uiDefButBitS(block, TOG, PAF_FACE, B_CALCEFFECT, "Faces",       75,50,75,20, &paf->flag, 0, 0, 0, 0, "Emit particles from faces");
2028         if(paf->flag & PAF_FACE) {
2029                 uiDefButBitS(block, TOG, PAF_TRAND, B_CALCEFFECT, "Rand",       0,30,50,20, &paf->flag, 0, 0, 0, 0, "Use true random distribution from faces");
2030                 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");
2031                 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)");
2032         }
2033         else uiBlockEndAlign(block);    /* vgroup button no align */
2034         
2035         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");
2036         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)OBACT);
2037         uiBlockEndAlign(block);
2038         
2039         /* right collumn */
2040         uiBlockBeginAlign(block);
2041         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)");
2042         if(paf->flag & PAF_STATIC) {
2043                 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");
2044         }
2045         uiBlockEndAlign(block);
2046
2047         uiDefBut(block, LABEL, 0, "Display:",                           160,150,75,20, NULL, 0.0, 0, 0, 0, "");
2048         uiBlockBeginAlign(block);
2049         uiDefButS(block, NUM, B_CALCEFFECT, "Material:",        160,130,150,20, &paf->omat, 1.0, 16.0, 0, 0, "Specify material used for the particles");
2050         uiDefButS(block, TOG|BIT|7, B_REDR, "Mesh",                     160,110,50,20, &paf->flag, 0, 0, 0, 0, "Render emitter Mesh also");
2051         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");
2052         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");
2053         uiDefButS(block, TOG, REDRAWVIEW3D, "Vect",                     160,90,75,20, &paf->stype, 0, 0, 0, 0, "Give the particles a direction and rotation");
2054         uiDefButF(block, NUM, B_DIFF,           "Size:",                235,90,75,20, &paf->vectsize, 0.0, 1.0, 10, 1, "The amount the Vect option influences halo size");      
2055         uiBlockEndAlign(block);
2056
2057         uiDefBut(block, LABEL, 0, "Children:",                          160,70,75,20, NULL, 0.0, 0, 0, 0, "");
2058         uiBlockBeginAlign(block);
2059         uiDefButS(block, NUM, B_REDR,           "Generation:",  160,50,150,20, &paf->curmult, 0.0, 3.0, 0, 0, "Current generation of particles");
2060         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");
2061         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.");
2062         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");
2063         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");
2064         uiBlockEndAlign(block);
2065         
2066 }
2067
2068 /* NT - Panel for fluidsim settings */
2069 static void object_panel_fluidsim(Object *ob)
2070 {
2071         uiBlock *block;
2072         int yline = 160;
2073         const int lineHeight = 20;
2074         const int separateHeight = 3;
2075         const int objHeight = 20;
2076         
2077         block= uiNewBlock(&curarea->uiblocks, "object_fluidsim", UI_EMBOSS, UI_HELV, curarea->win);
2078         uiNewPanelTabbed("Soft Body", "Physics");
2079         if(uiNewPanel(curarea, block, "Fluid Simulation", "Physics", 1060, 0, 318, 204)==0) return;
2080
2081         uiDefButBitS(block, TOG, OB_FLUIDSIM_ENABLE, REDRAWBUTSOBJECT, "Enable",         0,yline, 75,objHeight, 
2082                         &ob->fluidsimFlag, 0, 0, 0, 0, "Sets object to participate in fluid simulation");
2083
2084         if(ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) {
2085                 FluidsimSettings *fss= ob->fluidsimSettings;
2086                 
2087                 if(fss==NULL) {
2088                         fss = ob->fluidsimSettings = fluidsimSettingsNew(ob);
2089                 }
2090
2091                 if(ob->type==OB_MESH) {
2092
2093                         uiBlockBeginAlign(block);
2094                         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.");
2095                         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.");
2096                         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.");
2097                         yline -= lineHeight;
2098
2099                         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.");
2100                         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.");
2101                         uiBlockEndAlign(block);
2102                         yline -= lineHeight;
2103                         yline -= 2*separateHeight;
2104
2105                         /* display specific settings for each type */
2106                         if(fss->type == OB_FLUIDSIM_DOMAIN) {
2107                                 const int maxRes = 512;
2108                                 char memString[32];
2109
2110                                 // use mesh bounding box and object scaling
2111                                 // TODO fix redraw issue
2112                                 elbeemEstimateMemreq(fss->resolutionxyz, 
2113                                                 ob->fluidsimSettings->bbSize[0],ob->fluidsimSettings->bbSize[1],ob->fluidsimSettings->bbSize[2], fss->maxRefine, memString);
2114                                 
2115                                 uiDefButBitS(block, TOG, 1, REDRAWBUTSOBJECT, "Advanced>>",      0,yline, 75,objHeight, &fss->show_advancedoptions, 0, 0, 0, 0, "Show advanced domain options.");
2116                                 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.");
2117                                 yline -= lineHeight;
2118                                 yline -= 2*separateHeight;
2119
2120                                 if(fss->show_advancedoptions == 0) {
2121                                         uiDefBut(block, LABEL,   0, "Req. BAKE Memory:",  0,yline,150,objHeight, NULL, 0.0, 0, 0, 0, "");
2122                                         uiDefBut(block, LABEL,   0, memString,  200,yline,100,objHeight, NULL, 0.0, 0, 0, 0, "");
2123                                         yline -= lineHeight;
2124
2125                                         uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Resolution:", 0, yline,150,objHeight, &fss->resolutionxyz, 1, maxRes, 10, 0, "Domain resolution in X,Y and Z direction");
2126                                         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");
2127                                         yline -= lineHeight;
2128                                         yline -= 1*separateHeight;
2129
2130                                         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.");
2131                                         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.");
2132                                         yline -= lineHeight;
2133                                         yline -= 2*separateHeight;
2134
2135                                         uiDefBut(block, LABEL,   0, "Disp.-Qual.:",              0,yline, 90,objHeight, NULL, 0.0, 0, 0, 0, "");
2136                                         uiDefButS(block, MENU, B_FLUIDSIM_FORCEREDRAW, "GuiDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",   
2137                                                          90,yline,105,objHeight, &fss->guiDisplayMode, 0, 0, 0, 0, "How to display the fluid mesh in the blender gui.");
2138                                         uiDefButS(block, MENU, B_DIFF, "RenderDisplayMode%t|Geometry %x1|Preview %x2|Final %x3",        
2139                                                         195,yline,105,objHeight, &fss->renderDisplayMode, 0, 0, 0, 0, "How to display the fluid mesh for rendering.");
2140                                         yline -= lineHeight;
2141                                         yline -= 1*separateHeight;
2142
2143                                         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");
2144                                         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");
2145                                         // FIXME what is the 79.0 above?
2146                                 } else {
2147                                         // advanced options
2148                                         uiBlockBeginAlign(block);
2149                                         uiDefBut(block, LABEL, 0, "Gravity:",           0, yline,  90,objHeight, NULL, 0.0, 0, 0, 0, "");
2150                                         uiDefButF(block, NUM, B_DIFF, "X:",    90, yline,  70,objHeight, &fss->gravx, -1000.1, 1000.1, 10, 0, "Gravity in X direction");
2151                                         uiDefButF(block, NUM, B_DIFF, "Y:",   160, yline,  70,objHeight, &fss->gravy, -1000.1, 1000.1, 10, 0, "Gravity in Y direction");
2152                                         uiDefButF(block, NUM, B_DIFF, "Z:",   230, yline,  70,objHeight, &fss->gravz, -1000.1, 1000.1, 10, 0, "Gravity in Z direction");
2153                                         uiBlockEndAlign(block);
2154                                         yline -= lineHeight;
2155                                         yline -= 1*separateHeight;
2156
2157                                         /* viscosity */
2158                                         uiBlockBeginAlign(block);
2159                                         uiDefButS(block, MENU, REDRAWVIEW3D, "Viscosity%t|Manual %x1|Water %x2|Oil %x3|Honey %x4",      
2160                                                         0,yline, 90,objHeight, &fss->viscosityMode, 0, 0, 0, 0, "Set viscosity of the fluid to a preset value, or use manual input.");
2161                                         if(fss->viscosityMode==1) {
2162                                                 uiDefButF(block, NUM, B_DIFF, "Value:",     90, yline, 105,objHeight, &fss->viscosityValue,       0.0, 1.0, 10, 0, "Viscosity setting, value that is multiplied by 10 to the power of (exponent*-1).");
2163                                                 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.");
2164                                         } else {
2165                                                 // display preset values
2166                                                 uiDefBut(block, LABEL,   0, fluidsimViscosityPresetString[fss->viscosityMode],  90,yline,200,objHeight, NULL, 0.0, 0, 0, 0, "");
2167                                         }
2168                                         uiBlockEndAlign(block);
2169                                         yline -= lineHeight;
2170                                         yline -= 1*separateHeight;
2171
2172                                         uiDefBut(block, LABEL, 0, "Realworld-size:",            0,yline,150,objHeight, NULL, 0.0, 0, 0, 0, "");
2173                                         uiDefButF(block, NUM, B_DIFF, "", 150, yline,150,objHeight, &fss->realsize, 0.001, 1.0, 10, 0, "Size of the simulation domain in meters.");
2174                                         yline -= lineHeight;
2175                                         yline -= 2*separateHeight;
2176
2177                                         uiDefBut(block, LABEL, 0, "Gridlevels:",                0,yline,150,objHeight, NULL, 0.0, 0, 0, 0, "");
2178                                         uiDefButI(block, NUM, B_DIFF, "", 150, yline,150,objHeight, &fss->maxRefine, -1, 4, 10, 0, "Number of coarsened Grids to use (set to -1 for automatic selection).");
2179                                         yline -= lineHeight;
2180
2181                                         uiDefBut(block, LABEL, 0, "Compressibility:",           0,yline,150,objHeight, NULL, 0.0, 0, 0, 0, "");
2182                                         uiDefButF(block, NUM, B_DIFF, "", 150, yline,150,objHeight, &fss->gstar, 0.001, 0.10, 10,0, "Allowed compressibility due to gravitational force for standing fluid (directly affects simulation step size).");
2183                                         yline -= lineHeight;
2184
2185                                 }
2186                         }
2187                         else if(
2188                                         (fss->type == OB_FLUIDSIM_FLUID) 
2189                                         || (fss->type == OB_FLUIDSIM_INFLOW) 
2190                                         ) {
2191                                 yline -= lineHeight + 5;
2192                                 if(fss->type == OB_FLUIDSIM_FLUID)  uiDefBut(block, LABEL, 0, "Initial velocity:",              0,yline,200,objHeight, NULL, 0.0, 0, 0, 0, "");
2193                                 if(fss->type == OB_FLUIDSIM_INFLOW) uiDefBut(block, LABEL, 0, "Inflow velocity:",                 0,yline,200,objHeight, NULL, 0.0, 0, 0, 0, "");
2194                                 yline -= lineHeight;
2195                                 uiBlockBeginAlign(block);
2196                                 uiDefButF(block, NUM, B_DIFF, "X:",   0, yline, 100,objHeight, &fss->iniVelx, -1000.1, 1000.1, 10, 0, "Fluid velocity in X direction");
2197                                 uiDefButF(block, NUM, B_DIFF, "Y:", 100, yline, 100,objHeight, &fss->iniVely, -1000.1, 1000.1, 10, 0, "Fluid velocity in Y direction");
2198                                 uiDefButF(block, NUM, B_DIFF, "Z:", 200, yline, 100,objHeight, &fss->iniVelz, -1000.1, 1000.1, 10, 0, "Fluid velocity in Z direction");
2199                                 uiBlockEndAlign(block);
2200                                 yline -= lineHeight;
2201                         }
2202                         else if(
2203                                         (fss->type == OB_FLUIDSIM_OBSTACLE) 
2204                                         || (fss->type == OB_FLUIDSIM_OUTFLOW) 
2205                                 )       {
2206                                 yline -= lineHeight + 5;
2207                                 uiDefBut(block, LABEL, 0, "No additional settings as of now...",                0,yline,300,objHeight, NULL, 0.0, 0, 0, 0, "");
2208                                 yline -= lineHeight;
2209                         }
2210                         else {
2211                                 yline -= lineHeight + 5;
2212                                 /* not yet set */
2213                                 uiDefBut(block, LABEL, 0, "Select object type for simulation",          0,yline,300,objHeight, NULL, 0.0, 0, 0, 0, "");
2214                                 yline -= lineHeight;
2215                         }
2216
2217                 } else {
2218                         yline -= lineHeight + 5;
2219                         uiDefBut(block, LABEL, 0, "Sorry - only meshes supported", 0,yline,300,objHeight, NULL, 0.0, 0, 0, 0, "");
2220                         yline -= lineHeight;
2221                 }
2222         } else {
2223                 yline -= lineHeight + 5;
2224                 uiDefBut(block, LABEL, 0, "Object not enabled for fluid simulation...", 0,yline,300,objHeight, NULL, 0.0, 0, 0, 0, "");
2225                 yline -= lineHeight;
2226         }
2227 }
2228
2229 void object_panels()
2230 {
2231         Object *ob;
2232
2233         /* check context here */
2234         ob= OBACT;
2235         if(ob) {
2236                 if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2237
2238                 object_panel_anim(ob);
2239                 object_panel_draw(ob);
2240                 object_panel_constraint("Object");
2241
2242                 uiClearButLock();
2243         }
2244 }
2245
2246 void physics_panels()
2247 {
2248         Object *ob;
2249         
2250         /* check context here */
2251         ob= OBACT;
2252         if(ob) {
2253                 if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2254                 object_panel_fields(ob);
2255                 object_panel_particles(ob);
2256                 object_panel_particles_motion(ob);
2257                 object_softbodies(ob);
2258                 object_panel_fluidsim(ob);
2259         }
2260 }
2261