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