surface objects are allowed to be softbodies too
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "MEM_guardedalloc.h"
43
44 #include "DNA_ID.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "BKE_action.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_library.h"
53 #include "BKE_softbody.h"
54 #include "BKE_utildefines.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58
59 #include "BSE_filesel.h"
60 #include "BSE_headerbuttons.h"
61
62 #include "BIF_butspace.h"
63 #include "BIF_editaction.h"
64 #include "BIF_gl.h"
65 #include "BIF_glutil.h"
66 #include "BIF_graphics.h"
67 #include "BIF_interface.h"
68 #include "BIF_keyval.h"
69 #include "BIF_mainqueue.h"
70 #include "BIF_mywindow.h"
71 #include "BIF_poseobject.h"
72 #include "BIF_resources.h"
73 #include "BIF_screen.h"
74 #include "BIF_space.h"
75 #include "BIF_toolbox.h"
76
77 #include "BDR_drawobject.h"
78 #include "BDR_editcurve.h"
79
80 #include "mydevice.h"
81 #include "blendef.h"
82
83 /* -----includes for this file specific----- */
84
85
86 #include "DNA_action_types.h"
87 #include "DNA_armature_types.h"
88 #include "DNA_camera_types.h"
89 #include "DNA_constraint_types.h"
90 #include "DNA_curve_types.h"
91 #include "DNA_effect_types.h"
92 #include "DNA_group_types.h"
93 #include "DNA_image_types.h"
94 #include "DNA_key_types.h"
95 #include "DNA_lamp_types.h"
96 #include "DNA_lattice_types.h"
97 #include "DNA_material_types.h"
98 #include "DNA_meta_types.h"
99 #include "DNA_mesh_types.h"
100 #include "DNA_modifier_types.h"
101 #include "DNA_object_types.h"
102 #include "DNA_object_force.h"
103 #include "DNA_object_fluidsim.h"
104 #include "DNA_radio_types.h"
105 #include "DNA_screen_types.h"
106 #include "DNA_sound_types.h"
107 #include "DNA_texture_types.h"
108 #include "DNA_userdef_types.h"
109 #include "DNA_vfont_types.h"
110 #include "DNA_view3d_types.h"
111 #include "DNA_world_types.h"
112
113 #include "BKE_anim.h"
114 #include "BKE_armature.h"
115 #include "BKE_constraint.h"
116 #include "BKE_curve.h"
117 #include "BKE_deform.h"
118 #include "BKE_depsgraph.h"
119 #include "BKE_displist.h"
120 #include "BKE_effect.h"
121 #include "BKE_font.h"
122 #include "BKE_group.h"
123 #include "BKE_image.h"
124 #include "BKE_ipo.h"
125 #include "BKE_lattice.h"
126 #include "BKE_material.h"
127 #include "BKE_mball.h"
128 #include "BKE_mesh.h"
129 #include "BKE_modifier.h"
130 #include "BKE_object.h"
131 #include "BKE_sound.h"
132 #include "BKE_texture.h"
133 #include "BKE_utildefines.h"
134 #include "BKE_DerivedMesh.h"
135
136 #include "LBM_fluidsim.h"
137 #include "elbeem.h"
138
139 #include "BIF_editconstraint.h"
140 #include "BIF_editdeform.h"
141
142 #include "BSE_editipo.h"
143 #include "BSE_edit.h"
144
145 #include "BDR_editobject.h"
146
147 #include "butspace.h" // own module
148
149 static float prspeed=0.0;
150 float prlen=0.0;
151
152
153 /* ********************* CONSTRAINT ***************************** */
154
155 static void constraint_active_func(void *ob_v, void *con_v)
156 {
157         Object *ob= ob_v;
158         bConstraint *con;
159         ListBase *lb;
160         
161         /* lets be nice and escape if its active already */
162         if(con_v) {
163                 con= con_v;
164                 if(con->flag & CONSTRAINT_ACTIVE) return;
165         }
166         
167         lb= get_active_constraints(ob);
168         
169         for(con= lb->first; con; con= con->next) {
170                 if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
171                 else con->flag &= ~CONSTRAINT_ACTIVE;
172         }
173
174         /* make sure ipowin and buttons shows it */
175         if(ob->ipowin==ID_CO) {
176                 allqueue(REDRAWIPO, ID_CO);
177                 allspace(REMAKEIPO, 0);
178                 allqueue(REDRAWNLA, 0);
179         }
180         allqueue(REDRAWBUTSOBJECT, 0);
181 }
182
183 static void add_constraint_to_active(Object *ob, bConstraint *con)
184 {
185         ListBase *list;
186         
187         list = get_active_constraints(ob);
188         if (list) {
189                 unique_constraint_name(con, list);
190                 BLI_addtail(list, con);
191                 
192                 con->flag |= CONSTRAINT_ACTIVE;
193                 for(con= con->prev; con; con= con->prev)
194                         con->flag &= ~CONSTRAINT_ACTIVE;
195         }
196 }
197
198 /* returns base ID for Ipo, sets actname to channel if appropriate */
199 /* should not make action... */
200 void get_constraint_ipo_context(void *ob_v, char *actname)
201 {
202         Object *ob= ob_v;
203         
204         /* todo; check object if it has ob-level action ipo */
205         
206         if (ob->flag & OB_POSEMODE) {
207                 bPoseChannel *pchan;
208                 
209                 pchan = get_active_posechannel(ob);
210                 if (pchan) {
211                         BLI_strncpy(actname, pchan->name, 32);
212                 }
213         }
214         else if(ob->ipoflag & OB_ACTION_OB)
215                 strcpy(actname, "Object");
216 }       
217
218 /* initialize UI to show Ipo window and make sure channels etc exist */
219 static void enable_constraint_ipo_func (void *ob_v, void *con_v)
220 {
221         Object *ob= ob_v;
222         bConstraint *con = con_v;
223         char actname[32]="";
224         
225         /* verifies if active constraint is set and shown in UI */
226         constraint_active_func(ob_v, con_v);
227         
228         /* the context */
229         get_constraint_ipo_context(ob, actname);
230         
231         /* adds ipo & channels & curve if needed */
232         verify_ipo((ID *)ob, ID_CO, actname, con->name);
233         
234         /* make sure ipowin shows it */
235         ob->ipowin= ID_CO;
236         allqueue(REDRAWIPO, ID_CO);
237         allspace(REMAKEIPO, 0);
238         allqueue(REDRAWNLA, 0);
239 }
240
241
242 static void add_influence_key_to_constraint_func (void *ob_v, void *con_v)
243 {
244         Object *ob= ob_v;
245         bConstraint *con = con_v;
246         IpoCurve *icu;
247         char actname[32]="";
248         
249         /* verifies if active constraint is set and shown in UI */
250         constraint_active_func(ob_v, con_v);
251         
252         /* the context */
253         get_constraint_ipo_context(ob, actname);
254
255         /* adds ipo & channels & curve if needed */
256         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
257         
258         if (!icu) {
259                 error("Cannot get a curve from this IPO, may be dealing with linked data");
260                 return;
261         }
262         
263         if(ob->action)
264                 insert_vert_ipo(icu, get_action_frame(ob, (float)CFRA), con->enforce);
265         else
266                 insert_vert_ipo(icu, CFRA, con->enforce);
267         
268         /* make sure ipowin shows it */
269         ob->ipowin= ID_CO;
270         allqueue(REDRAWIPO, ID_CO);
271         allspace(REMAKEIPO, 0);
272         allqueue(REDRAWNLA, 0);
273         
274         BIF_undo_push("Insert Influence Key");
275 }
276
277 void del_constr_func (void *ob_v, void *con_v)
278 {
279         bConstraint *con= con_v;
280         bConstraintChannel *chan;
281         ListBase *lb;
282         
283         /* remove ipo channel */
284         lb= get_active_constraint_channels(ob_v, 0);
285         if(lb) {
286                 chan = get_constraint_channel(lb, con->name);
287                 if(chan) {
288                         if(chan->ipo) chan->ipo->id.us--;
289                         BLI_freelinkN(lb, chan);
290                 }
291         }
292         /* remove constraint itself */
293         lb= get_active_constraints(ob_v);
294         free_constraint_data (con);
295         BLI_freelinkN(lb, con);
296         
297         constraint_active_func(ob_v, NULL);
298 }
299
300 static void del_constraint_func (void *ob_v, void *con_v)
301 {
302         del_constr_func (ob_v, con_v);
303         BIF_undo_push("Delete constraint");
304         allqueue(REDRAWBUTSOBJECT, 0);
305         allqueue(REDRAWIPO, 0); 
306 }
307
308 static void verify_constraint_name_func (void *con_v, void *name_v)
309 {
310         Object *ob= OBACT;
311         bConstraint *con= con_v;
312         char oldname[32];       
313         
314         if (!con)
315                 return;
316         
317         /* put on the stack */
318         BLI_strncpy(oldname, (char *)name_v, 32);
319         
320         rename_constraint(ob, con, oldname);
321         
322         constraint_active_func(ob, con);
323         allqueue(REDRAWACTION, 0); 
324 }
325
326 void get_constraint_typestring (char *str, void *con_v)
327 {
328         bConstraint *con= con_v;
329
330         switch (con->type){
331         case CONSTRAINT_TYPE_CHILDOF:
332                 strcpy (str, "Child Of");
333                 return;
334         case CONSTRAINT_TYPE_NULL:
335                 strcpy (str, "Null");
336                 return;
337         case CONSTRAINT_TYPE_TRACKTO:
338                 strcpy (str, "Track To");
339                 return;
340         case CONSTRAINT_TYPE_MINMAX:
341                 strcpy (str, "Floor");
342                 return;
343         case CONSTRAINT_TYPE_KINEMATIC:
344                 strcpy (str, "IK Solver");
345                 return;
346         case CONSTRAINT_TYPE_ROTLIKE:
347                 strcpy (str, "Copy Rotation");
348                 return;
349         case CONSTRAINT_TYPE_LOCLIKE:
350                 strcpy (str, "Copy Location");
351                 return;
352         case CONSTRAINT_TYPE_SIZELIKE:
353                 strcpy (str, "Copy Scale");
354                 return;
355         case CONSTRAINT_TYPE_ACTION:
356                 strcpy (str, "Action");
357                 return;
358         case CONSTRAINT_TYPE_LOCKTRACK:
359                 strcpy (str, "Locked Track");
360                 return;
361         case CONSTRAINT_TYPE_FOLLOWPATH:
362                 strcpy (str, "Follow Path");
363                 return;
364         case CONSTRAINT_TYPE_STRETCHTO:
365                 strcpy (str, "Stretch To");
366                 return;
367         case CONSTRAINT_TYPE_LOCLIMIT:
368                 strcpy (str, "Limit Location");
369                 return;
370         case CONSTRAINT_TYPE_ROTLIMIT:
371                 strcpy (str, "Limit Rotation");
372                 return;
373         case CONSTRAINT_TYPE_SIZELIMIT:
374                 strcpy (str, "Limit Scale");
375                 return;
376         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
377                 strcpy (str, "Rigid Body");
378                 return;
379         case CONSTRAINT_TYPE_CLAMPTO:
380                 strcpy (str, "Clamp To");
381                 return;
382         default:
383                 strcpy (str, "Unknown");
384                 return;
385         }
386 }
387
388 static int get_constraint_col(bConstraint *con)
389 {
390         switch (con->type) {
391         case CONSTRAINT_TYPE_NULL:
392                 return TH_BUT_NEUTRAL;
393         case CONSTRAINT_TYPE_KINEMATIC:
394                 return TH_BUT_SETTING2;
395         case CONSTRAINT_TYPE_TRACKTO:
396                 return TH_BUT_SETTING;
397         case CONSTRAINT_TYPE_ROTLIKE:
398                 return TH_BUT_SETTING1;
399         case CONSTRAINT_TYPE_LOCLIKE:
400                 return TH_BUT_POPUP;
401         case CONSTRAINT_TYPE_MINMAX:
402                 return TH_BUT_POPUP;
403         case CONSTRAINT_TYPE_SIZELIKE:
404                 return TH_BUT_POPUP;
405         case CONSTRAINT_TYPE_ACTION:
406                 return TH_BUT_ACTION;
407         case CONSTRAINT_TYPE_LOCKTRACK:
408                 return TH_BUT_SETTING;
409         case CONSTRAINT_TYPE_FOLLOWPATH:
410                 return TH_BUT_SETTING2;
411         case CONSTRAINT_TYPE_STRETCHTO:
412                 return TH_BUT_SETTING;
413         case CONSTRAINT_TYPE_LOCLIMIT:
414                 return TH_BUT_POPUP;
415         case CONSTRAINT_TYPE_ROTLIMIT:
416                 return TH_BUT_POPUP;
417         case CONSTRAINT_TYPE_SIZELIMIT:
418                 return TH_BUT_POPUP;
419         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
420                 return TH_BUT_SETTING;
421         default:
422                 return TH_REDALERT;
423         }
424 }
425
426 void const_moveUp(void *ob_v, void *con_v)
427 {
428         bConstraint *con, *constr= con_v;
429         ListBase *conlist;
430         
431         if(constr->prev) {
432                 conlist = get_active_constraints(ob_v);
433                 for(con= conlist->first; con; con= con->next) {
434                         if(con==constr) {
435                                 BLI_remlink(conlist, con);
436                                 BLI_insertlink(conlist, con->prev->prev, con);
437                                 break;
438                         }
439                 }
440         }
441 }
442
443 static void constraint_moveUp(void *ob_v, void *con_v)
444 {
445         const_moveUp(ob_v, con_v);
446         BIF_undo_push("Move constraint");
447 }
448
449 void const_moveDown(void *ob_v, void *con_v)
450 {
451         bConstraint *con, *constr= con_v;
452         ListBase *conlist;
453         
454         if(constr->next) {
455                 conlist = get_active_constraints(ob_v);
456                 for(con= conlist->first; con; con= con->next) {
457                         if(con==constr) {
458                                 BLI_remlink(conlist, con);
459                                 BLI_insertlink(conlist, con->next, con);
460                                 break;
461                         }
462                 }
463         }
464 }
465
466 static void constraint_moveDown(void *ob_v, void *con_v)
467 {
468         const_moveDown(ob_v, con_v);
469         BIF_undo_push("Move constraint");
470 }
471
472 /* autocomplete callback for  buttons */
473 void autocomplete_bone(char *str, void *arg_v)
474 {
475         Object *ob= (Object *)arg_v;
476         
477         if(ob==NULL || ob->pose==NULL) return;
478         
479         /* search if str matches the beginning of name */
480         if(str[0]) {
481                 AutoComplete *autocpl= autocomplete_begin(str, 32);
482                 bPoseChannel *pchan;
483                 
484                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
485                         autocomplete_do_name(autocpl, pchan->name);
486
487                 autocomplete_end(autocpl, str);
488         }
489 }
490
491 /* autocomplete callback for buttons */
492 void autocomplete_vgroup(char *str, void *arg_v)
493 {
494         Object *ob= (Object *)arg_v;
495         
496         if(ob==NULL) return;
497         
498         /* search if str matches the beginning of a name */
499         if(str[0]) {
500                 AutoComplete *autocpl= autocomplete_begin(str, 32);
501                 bDeformGroup *dg;
502                 
503                 for(dg= ob->defbase.first; dg; dg= dg->next)
504                         if(dg->name!=str)
505                                 autocomplete_do_name(autocpl, dg->name);
506
507                 autocomplete_end(autocpl, str);
508         }
509 }
510
511 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
512 {
513         Object *ob= OBACT, *target;
514         uiBut *but;
515         char typestr[64], *subtarget;
516         short height, width = 265, is_armature_target;
517         int curCol, rb_col;
518
519         target= get_constraint_target(con, &subtarget);
520         is_armature_target= (target && target->type==OB_ARMATURE);
521         
522         /* unless button has own callback, it adds this callback to button */
523         uiBlockSetFunc(block, constraint_active_func, ob, con);
524         
525         get_constraint_typestring (typestr, con);
526
527         curCol = get_constraint_col(con);
528
529         /* Draw constraint header */
530         uiBlockSetEmboss(block, UI_EMBOSSN);
531         
532         /* rounded header */
533         rb_col= (con->flag & CONSTRAINT_ACTIVE)?40:20;
534         uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-1, width+40, 22, NULL, 5.0, 0.0, 
535                          (con->flag & CONSTRAINT_EXPAND)?3:15 , rb_col-20, ""); 
536         
537         /* open/close */
538         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");
539         
540         /* up down */
541         uiBlockSetEmboss(block, UI_EMBOSS);
542         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");
543         uiButSetFunc(but, constraint_moveUp, ob, con);
544         
545         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");
546         uiButSetFunc(but, constraint_moveDown, ob, con);
547         
548         if (con->flag & CONSTRAINT_EXPAND) {
549                 
550                 if (con->flag & CONSTRAINT_DISABLE) {
551                         BIF_ThemeColor(TH_REDALERT);
552                         uiBlockSetCol(block, TH_REDALERT);
553                 }
554                 else {
555                         BIF_ThemeColor(curCol);
556                 }
557
558                 /*if (type==TARGET_BONE)
559                         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"); 
560                 else
561                         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"); 
562                 */
563                 uiBlockSetEmboss(block, UI_EMBOSS);
564                 
565                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
566                 
567                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
568                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
569         }       
570         else {
571                 uiBlockSetEmboss(block, UI_EMBOSSN);
572
573                 if (con->flag & CONSTRAINT_DISABLE) {
574                         uiBlockSetCol(block, TH_REDALERT);
575                         BIF_ThemeColor(TH_REDALERT);
576                 }
577                 else {
578                         BIF_ThemeColor(curCol);
579                 }
580                 
581                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
582                 
583                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
584         }
585
586         uiBlockSetCol(block, TH_AUTO);  
587         
588         uiBlockSetEmboss(block, UI_EMBOSSN);
589         
590         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");
591         uiButSetFunc(but, del_constraint_func, ob, con);
592
593         uiBlockSetEmboss(block, UI_EMBOSS);
594
595
596         /* Draw constraint data*/
597         if (!(con->flag & CONSTRAINT_EXPAND)) {
598                 (*yco)-=21;
599         }
600         else {
601                 switch (con->type){
602                 case CONSTRAINT_TYPE_ACTION:
603                         {
604                                 bActionConstraint *data = con->data;
605
606                                 height = 88;
607                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
608                                 
609                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
610
611                                 /* Draw target parameters */
612                                 uiBlockBeginAlign(block);
613                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
614
615                                 if (is_armature_target){
616                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
617                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
618                                 }
619                                 else {
620                                         strcpy (data->subtarget, "");
621                                 }
622                                 
623                                 uiBlockEndAlign(block);
624
625                                 /* Draw action button */
626                                 uiBlockBeginAlign(block);
627                                 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");
628                                 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"); 
629                                 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");
630
631                                 uiBlockBeginAlign(block);
632                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "Start:", *xco+((width/2)-36), *yco-64, 78, 18, &data->start, 1, MAXFRAME, 0.0, 0.0, "Starting frame of the keyed motion"); 
633                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "End:", *xco+((width/2)-36), *yco-84, 78, 18, &data->end, 1, MAXFRAME, 0.0, 0.0, "Ending frame of the keyed motion"); 
634                                 
635                                 uiBlockBeginAlign(block);
636                                 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");
637                                 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");
638                                 uiBlockEndAlign(block);
639                         }
640                         break;
641                 case CONSTRAINT_TYPE_LOCLIKE:
642                         {
643                                 bLocateLikeConstraint *data = con->data;
644                                 
645                                 height = 91;
646                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
647
648                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
649
650                                 /* Draw target parameters */
651                                 uiBlockBeginAlign(block);
652                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
653
654                                 if (is_armature_target) {
655                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
656                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
657                                 }
658                                 else {
659                                         strcpy (data->subtarget, "");
660                                 }
661                                 
662                                 uiBlockEndAlign(block);
663                                 
664                                 /* Draw XYZ toggles */
665                                 uiBlockBeginAlign(block);
666                                 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");
667                                 but=uiDefButBitI(block, TOG, LOCLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
668                                 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");
669                                 but=uiDefButBitI(block, TOG, LOCLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
670                                 but=uiDefButBitI(block, TOG, LOCLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
671                                 but=uiDefButBitI(block, TOG, LOCLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
672                                 uiBlockEndAlign(block);
673                                 
674                                 /* Draw options */
675                                 uiDefButBitI(block, TOG, LOCLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/3), *yco-89, (width/3), 18, &data->flag, 0, 24, 0, 0, "Add original location onto copied location");
676                                 if (is_armature_target) {
677                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco, *yco-89, (width/3), 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
678                                         uiDefButBitI(block, TOG, LOCLIKE_TIP, B_CONSTRAINT_TEST, "Target Bone Tip", *xco+(width/3*2), *yco-89, (width/3), 18, &data->flag, 0, 24, 0, 0, "Copy Location of Target Bone's Tip");
679                                 }
680                         }
681                         break;
682                 case CONSTRAINT_TYPE_ROTLIKE:
683                         {
684                                 bRotateLikeConstraint *data = con->data;
685                                 
686                                 height = 91;
687                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
688                                 
689                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
690
691                                 /* Draw target parameters */
692                                 uiBlockBeginAlign(block);
693                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
694
695                                 if (is_armature_target) {
696                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
697                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
698                                 }
699                                 else {
700                                         strcpy (data->subtarget, "");
701                                 }
702                                 
703                                 uiBlockEndAlign(block);
704                                 
705                                 /* Draw XYZ toggles */
706                                 uiBlockBeginAlign(block);
707                                 if (is_armature_target)          
708                     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");
709                                 but=uiDefButBitI(block, TOG, ROTLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
710                                 but=uiDefButBitI(block, TOG, ROTLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
711                                 but=uiDefButBitI(block, TOG, ROTLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
712                                 but=uiDefButBitI(block, TOG, ROTLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
713                                 but=uiDefButBitI(block, TOG, ROTLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
714                                 but=uiDefButBitI(block, TOG, ROTLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
715                                 uiBlockEndAlign(block);
716                         }
717                         break;
718                 case CONSTRAINT_TYPE_SIZELIKE:
719                         {
720                                 bSizeLikeConstraint *data = con->data;
721                                 height = 91;
722                         
723                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
724
725                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
726
727                                 /* Draw target parameters */
728                                 uiBlockBeginAlign(block);
729                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
730                                 
731                                 if (is_armature_target) {
732                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
733                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
734                                 }
735                                 else {
736                                         strcpy (data->subtarget, "");
737                                 }
738                                 
739                                 uiBlockEndAlign(block);
740
741                                 /* Draw XYZ toggles */
742                                 uiBlockBeginAlign(block);
743                                 if (is_armature_target)
744                                         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");
745                                 but=uiDefButBitI(block, TOG, SIZELIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
746                                 but=uiDefButBitI(block, TOG, SIZELIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
747                                 but=uiDefButBitI(block, TOG, SIZELIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
748                                 uiBlockEndAlign(block);
749                         }
750                         break;
751                 case CONSTRAINT_TYPE_KINEMATIC:
752                         {
753                                 bKinematicConstraint *data = con->data;
754                                 
755                                 height = 111;
756                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
757                                 
758                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
759
760                                 /* Draw target parameters */
761                                 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");
762                                 
763                                 uiBlockBeginAlign(block);
764                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 19, &data->tar, "Target Object"); 
765
766                                 if (is_armature_target) {
767                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,19, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
768                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
769                                 }
770                                 else {
771                                         strcpy (data->subtarget, "");
772                                 }
773         
774                                 uiBlockBeginAlign(block);
775                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_TIP, B_CONSTRAINT_TEST, "Use Tip", *xco, *yco-64, 137, 19, &data->flag, 0, 0, 0, 0, "Include Bone's tip als last element in Chain");
776                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "ChainLen:", *xco, *yco-84,137,19, &data->rootbone, 0, 255, 0, 0, "If not zero, the amount of bones in this chain");
777                                 
778                                 uiBlockBeginAlign(block);
779                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "PosW ", *xco+147, *yco-64, 137, 19, &data->weight, 0.01, 1.0, 2, 2, "For Tree-IK: weight of position control for this target");
780                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "RotW ", *xco+147, *yco-84, 137, 19, &data->orientweight, 0.01, 1.0, 2, 2, "For Tree-IK: Weight of orientation control for this target");
781
782                                 uiBlockBeginAlign(block);
783                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "Iterations:", *xco, *yco-109, 137, 19, &data->iterations, 1, 10000, 0, 0, "Maximum number of solving iterations"); 
784                                 uiBlockBeginAlign(block);
785                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_STRETCH, B_CONSTRAINT_TEST, "Stretch", *xco+147, *yco-109,137,19, &data->flag, 0, 0, 0, 0, "Enable IK stretching");
786                                 
787                         }
788                         break;
789                 case CONSTRAINT_TYPE_TRACKTO:
790                         {
791                                 bTrackToConstraint *data = con->data;
792
793                                 height = 66;
794                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
795                                 
796                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
797
798                                 /* Draw target parameters */
799                                 uiBlockBeginAlign(block);
800                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
801
802                                 if (is_armature_target) {
803                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
804                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
805                                 }
806                                 else {
807                                         strcpy (data->subtarget, "");
808                                 }
809                                 
810                                 uiBlockEndAlign(block);
811
812                                 uiBlockBeginAlign(block);
813                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Align:", *xco+5, *yco-42, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
814
815                                 uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "TargetZ", *xco+60, *yco-42, 50, 18, &data->flags, 0, 1, 0, 0, "Target Z axis, not world Z axis, will constrain up direction");
816                                 uiBlockEndAlign(block);
817
818                                 uiBlockBeginAlign(block);
819                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
820                                 
821                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->reserved1, 12.0, 0.0, 0, 0, "X axis points to the target object");
822                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->reserved1, 12.0, 1.0, 0, 0, "Y axis points to the target object");
823                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->reserved1, 12.0, 2.0, 0, 0, "Z axis points to the target object");
824                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->reserved1, 12.0, 3.0, 0, 0, "-X axis points to the target object");
825                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->reserved1, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
826                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->reserved1, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
827                                 uiBlockEndAlign(block);
828                                 
829                                 uiBlockBeginAlign(block);
830                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
831                                 
832                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->reserved2, 13.0, 0.0, 0, 0, "X axis points upward");
833                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->reserved2, 13.0, 1.0, 0, 0, "Y axis points upward");
834                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->reserved2, 13.0, 2.0, 0, 0, "Z axis points upward");
835                                 uiBlockEndAlign(block);
836                         }
837                         break;
838                 case CONSTRAINT_TYPE_MINMAX:
839                         {
840                                 bMinMaxConstraint *data = con->data;
841
842                                 height = 66;
843                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
844                                 
845                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
846
847                                 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"); 
848
849                                 /* Draw target parameters */
850                                 uiBlockBeginAlign(block);
851                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
852
853                                 if (is_armature_target) {
854                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
855                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
856                                 }
857                                 else {
858                                         strcpy (data->subtarget, "");
859                                 }
860                                 
861                                 uiBlockEndAlign(block);
862
863                                 but=uiDefButI(block, TOG|BIT|0, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 44, 18, &data->flag, 0, 24, 0, 0, "Immobilize object while constrained");
864                                 but=uiDefButI(block, TOG|BIT|2, B_CONSTRAINT_TEST, "Use Rot", *xco+44, *yco-24, 64, 18, &data->flag, 0, 24, 0, 0, "Use target object rotation");
865                                 
866                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
867
868                                 uiBlockBeginAlign(block);                       
869                                 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");
870                                 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");
871                                 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");
872                                 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");
873                                 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");
874                                 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");
875                                 uiBlockEndAlign(block);
876                         }
877                         break;
878                 case CONSTRAINT_TYPE_LOCKTRACK:
879                         {
880                                 bLockTrackConstraint *data = con->data;
881                                 height = 66;
882                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
883
884                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
885
886                                 /* Draw target parameters */
887                                 uiBlockBeginAlign(block);
888                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
889
890                                 if (is_armature_target) {
891                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
892                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
893                                 }
894                                 else {
895                                         strcpy (data->subtarget, "");
896                                 }
897                                 
898                                 uiBlockEndAlign(block);
899                                 
900                                 uiBlockBeginAlign(block);
901                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
902                                 
903                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "X axis points to the target object");
904                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "Y axis points to the target object");
905                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "Z axis points to the target object");
906                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "-X axis points to the target object");
907                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
908                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
909                                 uiBlockEndAlign(block);
910                                 
911                                 uiBlockBeginAlign(block);
912                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
913                                 
914                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->lockflag, 13.0, 0.0, 0, 0, "X axis is locked");
915                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->lockflag, 13.0, 1.0, 0, 0, "Y axis is locked");
916                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->lockflag, 13.0, 2.0, 0, 0, "Z axis is locked");
917                                 uiBlockEndAlign(block);
918                         }
919                         break;
920                 case CONSTRAINT_TYPE_FOLLOWPATH:
921                         {
922                                 bFollowPathConstraint *data = con->data;
923
924                                 height = 66;
925                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
926                                 
927                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
928
929                                 /* Draw target parameters */
930                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
931                                 
932                                 /* Draw Curve Follow toggle */
933                                 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");
934
935                                 /* Draw Offset number button */
936                                 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"); 
937
938                                 uiBlockBeginAlign(block);
939                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
940                                 
941                                 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");
942                                 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");
943                                 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");
944                                 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");
945                                 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");
946                                 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");
947                                 uiBlockEndAlign(block);
948                                 
949                                 uiBlockBeginAlign(block);
950                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
951                                 
952                                 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");
953                                 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");
954                                 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");
955                                 uiBlockEndAlign(block);
956                         }
957                         break;
958                 case CONSTRAINT_TYPE_STRETCHTO:
959                         {
960                                 bStretchToConstraint *data = con->data;
961                                 
962                                 height = 105;
963                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
964                                 
965                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
966
967                                 /* Draw target parameters */
968                                 uiBlockBeginAlign(block);
969                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
970
971                                 if (is_armature_target) {
972                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
973                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
974                                 }
975                                 else {
976                                         strcpy (data->subtarget, "");
977                                 }
978                                 
979                                 uiBlockEndAlign(block);
980
981                                 
982                                 uiBlockBeginAlign(block);
983                                 uiDefButF(block,BUTM,B_CONSTRAINT_TEST,"R",*xco, *yco-60,20,18,&(data->orglength),0.0,0,0,0,"Recalculate RLength");
984                                 uiDefButF(block,NUM,B_CONSTRAINT_TEST,"Rest Length:",*xco+18, *yco-60,237,18,&(data->orglength),0.0,100,0.5,0.5,"Length at Rest Position");
985                                 uiBlockEndAlign(block);
986
987                                 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");
988
989                                 uiBlockBeginAlign(block);
990                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Vol:",*xco+14, *yco-104,30,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
991                                 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");
992                                 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");
993                                 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");
994                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"NONE", *xco+114, *yco-104,50,18, &data->volmode, 12.0, 3.0, 0, 0, "Ignore Volume");
995                                 uiBlockEndAlign(block);
996
997                                 
998                                 uiBlockBeginAlign(block);
999                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Plane:",*xco+175, *yco-104,40,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1000                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",       *xco+215, *yco-104,20,18, &data->plane, 12.0, 0.0, 0, 0, "Keep X axis");
1001                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",       *xco+235, *yco-104,20,18, &data->plane, 12.0, 2.0, 0, 0, "Keep Z axis");
1002                                 uiBlockEndAlign(block);
1003                                 }
1004                         break;
1005                 case CONSTRAINT_TYPE_LOCLIMIT:
1006                         {
1007                                 bLocLimitConstraint *data = con->data;
1008                                 
1009                                 int togButWidth = 50;
1010                                 int textButWidth = ((width/2)-togButWidth);
1011                                 
1012                                 height = 106; 
1013                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1014                                 
1015                                 /* Draw Pairs of LimitToggle+LimitValue */
1016                                 uiBlockBeginAlign(block); 
1017                                 uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1018                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), -1000, 1000, 0.1,0.5,"Lowest x value to allow"); 
1019                                 uiBlockEndAlign(block); 
1020                                 
1021                                 uiBlockBeginAlign(block); 
1022                                 uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1023                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), -1000, 1000, 0.1,0.5,"Highest x value to allow"); 
1024                                 uiBlockEndAlign(block); 
1025                                 
1026                                 uiBlockBeginAlign(block); 
1027                                 uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1028                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), -1000, 1000, 0.1,0.5,"Lowest y value to allow"); 
1029                                 uiBlockEndAlign(block);
1030                                 
1031                                 uiBlockBeginAlign(block); 
1032                                 uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1033                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), -1000, 1000, 0.1,0.5,"Highest y value to allow"); 
1034                                 uiBlockEndAlign(block); 
1035                                 
1036                                 uiBlockBeginAlign(block); 
1037                                 uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1038                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), -1000, 1000, 0.1,0.5,"Lowest z value to allow"); 
1039                                 uiBlockEndAlign(block);
1040                                 
1041                                 uiBlockBeginAlign(block); 
1042                                 uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1043                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), -1000, 1000, 0.1,0.5,"Highest z value to allow"); 
1044                                 uiBlockEndAlign(block);
1045                                 
1046                                 uiBlockBeginAlign(block);
1047                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1048                                 
1049                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1050                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Limit locations relative to the bone's rest-position");
1051                                 else if (ob->parent != NULL)
1052                                         uiDefButBitS(block, TOG, LIMIT_NOPARENT, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &data->flag2, 0, 24, 0, 0, "Limit locations relative to parent, not origin/world");
1053                                 else 
1054                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"World",*xco+160, *yco-100,60,18, NULL, 0.0, 0.0, 0.0, 0.0, "Limit locations relative to origin/world"); 
1055                                 
1056                                 uiBlockEndAlign(block);
1057                         }
1058                         break;
1059                 case CONSTRAINT_TYPE_ROTLIMIT:
1060                         {
1061                                 bRotLimitConstraint *data = con->data;
1062                                 int normButWidth = (width/3);
1063                                 
1064                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1065                                         height = 106; 
1066                                 else
1067                                         height = 78;
1068                                 
1069                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1070                                 
1071                                 /* Draw Pairs of LimitToggle+LimitValue */
1072                                 uiBlockBeginAlign(block); 
1073                                 uiDefButBitS(block, TOG, LIMIT_XROT, B_CONSTRAINT_TEST, "LimitX", *xco, *yco-28, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on x-axis"); 
1074                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-28, normButWidth, 18, &(data->xmin), -360, 360, 0.1,0.5,"Lowest x value to allow"); 
1075                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-28, normButWidth, 18, &(data->xmax), -360, 360, 0.1,0.5,"Highest x value to allow"); 
1076                                 uiBlockEndAlign(block); 
1077                                 
1078                                 uiBlockBeginAlign(block); 
1079                                 uiDefButBitS(block, TOG, LIMIT_YROT, B_CONSTRAINT_TEST, "LimitY", *xco, *yco-50, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on y-axis"); 
1080                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-50, normButWidth, 18, &(data->ymin), -360, 360, 0.1,0.5,"Lowest y value to allow"); 
1081                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-50, normButWidth, 18, &(data->ymax), -360, 360, 0.1,0.5,"Highest y value to allow"); 
1082                                 uiBlockEndAlign(block); 
1083                                 
1084                                 uiBlockBeginAlign(block); 
1085                                 uiDefButBitS(block, TOG, LIMIT_ZROT, B_CONSTRAINT_TEST, "LimitZ", *xco, *yco-72, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on z-axis"); 
1086                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-72, normButWidth, 18, &(data->zmin), -360, 360, 0.1,0.5,"Lowest z value to allow"); 
1087                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-72, normButWidth, 18, &(data->zmax), -360, 360, 0.1,0.5,"Highest z value to allow"); 
1088                                 uiBlockEndAlign(block); 
1089                                 
1090                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE)) {
1091                                         uiBlockBeginAlign(block);
1092                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1093                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
1094                                         uiBlockEndAlign(block);
1095                                 }
1096                         }
1097                         break;
1098                 case CONSTRAINT_TYPE_SIZELIMIT:
1099                         {
1100                                 bSizeLimitConstraint *data = con->data;
1101                                 
1102                                 int togButWidth = 50;
1103                                 int textButWidth = ((width/2)-togButWidth);
1104                                 
1105                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1106                                         height = 106; 
1107                                 else
1108                                         height = 78;
1109                                         
1110                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1111                                 
1112                                 /* Draw Pairs of LimitToggle+LimitValue */
1113                                 uiBlockBeginAlign(block); 
1114                                 uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1115                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), 0.0001, 1000, 0.1,0.5,"Lowest x value to allow"); 
1116                                 uiBlockEndAlign(block); 
1117
1118                                 uiBlockBeginAlign(block); 
1119                                 uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1120                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), 0.0001, 1000, 0.1,0.5,"Highest x value to allow"); 
1121                                 uiBlockEndAlign(block); 
1122
1123
1124                                 uiBlockBeginAlign(block); 
1125                                 uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1126                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), 0.0001, 1000, 0.1,0.5,"Lowest y value to allow"); 
1127                                 uiBlockEndAlign(block); 
1128
1129                                 uiBlockBeginAlign(block); 
1130                                 uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1131                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), 0.0001, 1000, 0.1,0.5,"Highest y value to allow"); 
1132                                 uiBlockEndAlign(block); 
1133
1134
1135                                 uiBlockBeginAlign(block); 
1136                                 uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1137                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), 0.0001, 1000, 0.1,0.5,"Lowest z value to allow"); 
1138                                 uiBlockEndAlign(block); 
1139
1140                                 uiBlockBeginAlign(block); 
1141                                 uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1142                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), 0.0001, 1000, 0.1,0.5,"Highest z value to allow"); 
1143                                 uiBlockEndAlign(block);
1144                                 
1145                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE)) {
1146                                         uiBlockBeginAlign(block);
1147                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1148                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
1149                                         uiBlockEndAlign(block);
1150                                 }
1151                         }
1152                         break;
1153                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1154                         {
1155                                 bRigidBodyJointConstraint *data = con->data;
1156                                 float extremeLin = 999.f;
1157                                 float extremeAngX = 180.f;
1158                                 float extremeAngY = 45.f;
1159                                 float extremeAngZ = 45.f;
1160                                 int togButWidth = 70;
1161                                 int offsetY = 150;
1162                                 int textButWidth = ((width/2)-togButWidth);
1163
1164                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Generic (experimental)%x12",//|Extra Force%x6",
1165                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1166                 height = 140;
1167                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1168                                         height = 270;
1169                                 
1170                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1171
1172                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1173                                 uiDefButBitS(block, TOG, CONSTRAINT_DRAW_PIVOT, B_CONSTRAINT_TEST, "ShowPivot", *xco+135, *yco-50, 130, 18, &data->flag, 0, 24, 0, 0, "Show pivot position and rotation");                              
1174
1175                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1176                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1177                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1178                                 
1179                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -360, 360, 1500, 0.0, "Rotate pivot on X Axis (in degrees)");
1180                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -360, 360, 1500, 0.0, "Rotate pivot on Y Axis (in degrees)");
1181                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -360, 360, 1500, 0.0, "Rotate pivot on Z Axis (in degrees)");
1182                                 
1183                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF){
1184                                         /* Draw Pairs of LimitToggle+LimitValue */
1185                                         uiBlockBeginAlign(block); 
1186                                         uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1187                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit"); 
1188
1189                                         uiBlockBeginAlign(block); 
1190                                         uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1191                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit"); 
1192
1193                                         offsetY += 20;
1194                                         uiBlockBeginAlign(block); 
1195                                         uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1196                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit"); 
1197
1198                                         uiBlockBeginAlign(block); 
1199                                         uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1200                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit"); 
1201
1202                                         offsetY += 20;
1203                                         uiBlockBeginAlign(block); 
1204                                         uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1205                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit"); 
1206
1207                                         uiBlockBeginAlign(block); 
1208                                         uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1209                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit"); 
1210                                         offsetY += 20;
1211                         
1212                                         /* Draw Pairs of LimitToggle+LimitValue */
1213                                         uiBlockBeginAlign(block); 
1214                                         uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1215                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit"); 
1216                                         uiBlockBeginAlign(block); 
1217                                         uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1218                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit"); 
1219
1220                                         offsetY += 20;
1221                                         uiBlockBeginAlign(block); 
1222                                         uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1223                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit"); 
1224
1225                                         uiBlockBeginAlign(block); 
1226                                         uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1227                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit"); 
1228
1229                                         offsetY += 20;
1230                                         uiBlockBeginAlign(block); 
1231                                         uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1232                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit"); 
1233
1234                                         uiBlockBeginAlign(block); 
1235                                         uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1236                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit"); 
1237                                         uiBlockEndAlign(block);
1238                                 }
1239                         }
1240                         break;
1241                 case CONSTRAINT_TYPE_CLAMPTO:
1242                         {
1243                                 bClampToConstraint *data = con->data;
1244                                 
1245                                 height = 66;
1246                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1247                                 
1248                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1249
1250                                 /* Draw target parameters */
1251                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1252                                 
1253                                 /* Draw XYZ toggles */
1254                                 uiBlockBeginAlign(block);
1255                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1256                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Auto", *xco+100, *yco-64, 50, 18, &data->flag, 12.0, CLAMPTO_AUTO, 0, 0, "Automatically determine main-axis of movement");
1257                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "X", *xco+150, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_X, 0, 0, "Main axis of movement is x-axis");
1258                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Y", *xco+182, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Y, 0, 0, "Main axis of movement is y-axis");
1259                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Z", *xco+214, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Z, 0, 0, "Main axis of movement is z-axis");
1260                                 uiBlockEndAlign(block);
1261                         }
1262                         break;
1263                 case CONSTRAINT_TYPE_NULL:
1264                         {
1265                                 height = 17;
1266                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1267                                 
1268                         }
1269                         break;
1270                 default:
1271                         height = 0;
1272                         break;
1273                 }
1274
1275                 (*yco)-=(24+height);
1276         }
1277
1278         if ((con->type != CONSTRAINT_TYPE_NULL) && (con->type!=CONSTRAINT_TYPE_RIGIDBODYJOINT)) {
1279                 uiBlockBeginAlign(block);
1280                 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");
1281                 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");
1282                 /* If this is on an object or bone, add ipo channel the constraint */
1283                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1284                 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");
1285                 /* Add a keyframe to the influence IPO */
1286                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1287                 uiBlockEndAlign(block);
1288                 (*yco)-=24;
1289         } 
1290         else {
1291                 (*yco)-=3;
1292         }
1293 }
1294
1295 static uiBlock *add_constraintmenu(void *arg_unused)
1296 {
1297         Object *ob= OBACT;
1298         uiBlock *block;
1299         ListBase *conlist;
1300         short yco= 0;
1301         
1302         conlist = get_active_constraints(ob);
1303         
1304         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1305
1306         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE,"Copy Location",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1307         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE,"Copy Rotation",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1308         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE,"Copy Scale",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1309         
1310         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1311         
1312         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT,"Limit Location",               0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1313         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT,"Limit Rotation",               0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1314         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT,"Limit Scale",                 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1315         
1316         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1317         
1318         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO,"Track To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1319         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX,"Floor",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1320         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK,"Locked Track",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1321         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH,"Follow Path",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1322         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO,"Clamp To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1323         
1324         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1325         
1326         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO,"Stretch To",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1327
1328         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT,"Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1329
1330         if (ob->flag & OB_POSEMODE) {
1331                 uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1332                 
1333                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC,"IK Solver",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1334                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION,"Action",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1335                 
1336         }
1337         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1338
1339         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL,"Null",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1340         
1341         uiTextBoundsBlock(block, 50);
1342         uiBlockSetDirection(block, UI_DOWN);
1343                 
1344         return block;
1345 }
1346
1347 void do_constraintbuts(unsigned short event)
1348 {
1349         Object *ob= OBACT;
1350         
1351         switch(event) {
1352         case B_CONSTRAINT_TEST:
1353                 break;  // no handling
1354         case B_CONSTRAINT_INF:
1355                 /* influence; do not execute actions for 1 dag_flush */
1356                 if(ob->pose)
1357                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1358
1359         case B_CONSTRAINT_CHANGETARGET:
1360                 if(ob->pose) ob->pose->flag |= POSE_RECALC;     // checks & sorts pose channels
1361                 DAG_scene_sort(G.scene);
1362                 break;
1363                 
1364         case B_CONSTRAINT_ADD_NULL:
1365                 {
1366                         bConstraint *con;
1367                         
1368                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1369                         add_constraint_to_active(ob, con);
1370
1371                         BIF_undo_push("Add constraint");
1372                 }
1373                 break;
1374         case B_CONSTRAINT_ADD_KINEMATIC:
1375                 {
1376                         bConstraint *con;
1377                         
1378                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1379                         add_constraint_to_active(ob, con);
1380
1381                         BIF_undo_push("Add constraint");
1382                 }
1383                 break;
1384         case B_CONSTRAINT_ADD_TRACKTO:
1385                 {
1386                         bConstraint *con;
1387
1388                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1389                         add_constraint_to_active(ob, con);
1390
1391                         BIF_undo_push("Add constraint");
1392                 }
1393                 break;
1394         case B_CONSTRAINT_ADD_MINMAX:
1395                 {
1396                         bConstraint *con;
1397
1398                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1399                         add_constraint_to_active(ob, con);
1400
1401                         BIF_undo_push("Add constraint");
1402                 }
1403                 break;
1404         case B_CONSTRAINT_ADD_ROTLIKE:
1405                 {
1406                         bConstraint *con;
1407
1408                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1409                         add_constraint_to_active(ob, con);
1410
1411                         BIF_undo_push("Add constraint");
1412                 }
1413                 break;
1414         case B_CONSTRAINT_ADD_LOCLIKE:
1415                 {
1416                         bConstraint *con;
1417
1418                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1419                         add_constraint_to_active(ob, con);
1420
1421                         BIF_undo_push("Add constraint");
1422                 }
1423                 break;
1424         case B_CONSTRAINT_ADD_SIZELIKE:
1425                 {
1426                         bConstraint *con;
1427  
1428                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1429                         add_constraint_to_active(ob, con);
1430   
1431                         BIF_undo_push("Add constraint");
1432                 }
1433                 break;
1434         case B_CONSTRAINT_ADD_ACTION:
1435                 {
1436                         bConstraint *con;
1437
1438                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1439                         add_constraint_to_active(ob, con);
1440
1441                         BIF_undo_push("Add constraint");
1442                 }
1443                 break;
1444         case B_CONSTRAINT_ADD_LOCKTRACK:
1445                 {
1446                         bConstraint *con;
1447
1448                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1449                         add_constraint_to_active(ob, con);
1450
1451                         BIF_undo_push("Add constraint");
1452                 }
1453                 break;
1454         case B_CONSTRAINT_ADD_FOLLOWPATH:
1455                 {
1456                         bConstraint *con;
1457
1458                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1459                         add_constraint_to_active(ob, con);
1460
1461                 }
1462                 break;
1463         case B_CONSTRAINT_ADD_STRETCHTO:
1464                 {
1465                         bConstraint *con;
1466                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1467                         add_constraint_to_active(ob, con);
1468                                 
1469                         BIF_undo_push("Add constraint");
1470                 }
1471                 break;
1472         case B_CONSTRAINT_ADD_LOCLIMIT:
1473                 {
1474                         bConstraint *con;
1475
1476                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
1477                         add_constraint_to_active(ob, con);
1478
1479                         BIF_undo_push("Add constraint");
1480                 }
1481                 break;
1482         case B_CONSTRAINT_ADD_ROTLIMIT:
1483                 {
1484                         bConstraint *con;
1485
1486                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
1487                         add_constraint_to_active(ob, con);
1488
1489                         BIF_undo_push("Add constraint");
1490                 }
1491                 break;
1492         case B_CONSTRAINT_ADD_SIZELIMIT:
1493                 {
1494                         bConstraint *con;
1495
1496                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
1497                         add_constraint_to_active(ob, con);
1498
1499                         BIF_undo_push("Add constraint");
1500                 }
1501                 break;
1502         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
1503                 {
1504                         bConstraint *con;
1505                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
1506                         add_constraint_to_active(ob, con);
1507
1508                         BIF_undo_push("Add constraint");
1509                 }
1510                 break;
1511         case B_CONSTRAINT_ADD_CLAMPTO:
1512                 {
1513                         bConstraint *con;
1514                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
1515                         add_constraint_to_active(ob, con);
1516
1517                         BIF_undo_push("Add constraint");
1518                 }
1519                 break;
1520
1521         default:
1522                 break;
1523         }
1524
1525         object_test_constraints(ob);
1526         
1527         if(ob->pose) update_pose_constraint_flags(ob->pose);
1528         
1529         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
1530         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1531         
1532         allqueue (REDRAWVIEW3D, 0);
1533         allqueue (REDRAWBUTSOBJECT, 0);
1534 }
1535
1536 void softbody_bake(Object *ob)
1537 {
1538         Base *base;
1539         SoftBody *sb;
1540         ScrArea *sa;
1541         float frameleno= G.scene->r.framelen;
1542         int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
1543         
1544         
1545         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
1546         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
1547         G.afbreek=0; // init global break system
1548         
1549         if(ob) {
1550                 sb= ob->soft;
1551                 sfra= MIN2(sfra, sb->sfra);
1552                 efra= MAX2(efra, sb->efra);
1553                 sbObjectToSoftbody(ob); // put softbody in restposition, free bake
1554                 ob->softflag |= OB_SB_BAKEDO;
1555         }
1556         else {
1557                 for(base=G.scene->base.first; base; base= base->next) {
1558                         if(TESTBASELIB(base)) {
1559                                 if(base->object->soft) {
1560                                         sb= base->object->soft;
1561                                         sfra= MIN2(sfra, sb->sfra);
1562                                         efra= MAX2(efra, sb->efra);
1563                                         sbObjectToSoftbody(base->object);       // put softbody in restposition, free bake
1564                                         base->object->softflag |= OB_SB_BAKEDO;
1565                                 }
1566                         }
1567                 }
1568         }
1569         
1570         CFRA= sfra;
1571         update_for_newframe_muted();    // put everything on this frame
1572         
1573         curarea->win_swap= 0;           // clean swapbuffers
1574         
1575         for(; CFRA <= efra; CFRA++) {
1576                 set_timecursor(CFRA);
1577                 
1578                 update_for_newframe_muted();
1579                 
1580                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
1581                         if(sa->spacetype == SPACE_VIEW3D) {
1582                                 scrarea_do_windraw(sa);
1583                         }
1584                 }
1585                 screen_swapbuffers();
1586                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
1587                 if (blender_test_break()){ 
1588                         didbreak = 1;
1589                         break;
1590                 }
1591
1592         }
1593         if((didbreak)&&(G.qual!=LR_SHIFTKEY)) {
1594                 if(ob) 
1595                         sbObjectToSoftbody(ob); // free bake
1596                 else {
1597                         for(base=G.scene->base.first; base; base= base->next) {
1598                                 if(TESTBASELIB(base)) {
1599                                         if(base->object->soft) {
1600                                                 sbObjectToSoftbody(base->object);       // free bake
1601                                         }
1602                                 }
1603                         }
1604                 }
1605         }
1606         
1607         /* restore */
1608         waitcursor(0);
1609         sbSetInterruptCallBack(NULL); // softbody module won't ESC
1610         G.afbreek=0; // reset global break system
1611         
1612         if(ob) 
1613                 ob->softflag &= ~OB_SB_BAKEDO;
1614         else {
1615                 for(base=G.scene->base.first; base; base= base->next)
1616                         if(TESTBASELIB(base))
1617                                 if(base->object->soft)
1618                                         base->object->softflag &= ~OB_SB_BAKEDO;
1619         }
1620         
1621         CFRA= cfrao;
1622         G.scene->r.framelen= frameleno;
1623         update_for_newframe_muted();
1624         allqueue(REDRAWVIEW3D, 0);
1625         allqueue(REDRAWBUTSOBJECT, 0);
1626 }
1627
1628 // store processed path & file prefix for fluidsim bake directory
1629 void fluidsimFilesel(char *selection)
1630 {
1631         Object *ob = OBACT;
1632         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
1633         char prefix[FILE_MAXFILE];
1634         char *srch, *srchSub, *srchExt, *lastFound;
1635         int isElbeemSurf = 0;
1636
1637         // make prefix
1638         strcpy(srcDir, selection);
1639         BLI_splitdirstring(srcDir, srcFile);
1640         strcpy(prefix, srcFile);
1641         // check if this is a previously generated surface mesh file
1642         srch = strstr(prefix, "fluidsurface_");
1643         // TODO search from back...
1644         if(srch) {
1645                 srchSub = strstr(prefix,"_preview_");
1646                 if(!srchSub) srchSub = strstr(prefix,"_final_");
1647                 srchExt = strstr(prefix,".gz.bobj");
1648                 if(!srchExt) srchExt = strstr(prefix,".bobj");
1649                 if(srchSub && srchExt) {
1650                         *srch = '\0';
1651                         isElbeemSurf = 1;
1652                 }
1653         }
1654         if(!isElbeemSurf) {
1655                 // try to remove suffix
1656                 lastFound = NULL;
1657                 srch = strchr(prefix, '.'); // search last . from extension
1658                 while(srch) {
1659                         lastFound = srch;
1660                         if(srch) {
1661                                 srch++;
1662                                 srch = strchr(srch, '.');
1663                         }
1664                 }
1665                 if(lastFound) {
1666                         *lastFound = '\0';
1667                 } 
1668         }
1669
1670         if(ob->fluidsimSettings) {
1671                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
1672                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
1673                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
1674
1675                 // redraw view & buttons...
1676                 allqueue(REDRAWBUTSOBJECT, 0);
1677                 allqueue(REDRAWVIEW3D, 0);
1678                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1679         }
1680 }
1681
1682 void do_object_panels(unsigned short event)
1683 {
1684         Object *ob;
1685         Effect *eff;
1686         
1687         ob= OBACT;
1688         if(ob==NULL)
1689                 return;
1690         
1691         switch(event) {
1692         case B_TRACKBUTS:
1693                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1694                 allqueue(REDRAWVIEW3D, 0);
1695                 break;
1696         case B_RECALCPATH:
1697                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1698                 allqueue(REDRAWVIEW3D, 0);
1699                 break;
1700         case B_DUPLI_FRAME:
1701                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
1702                 allqueue(REDRAWVIEW3D, 0);
1703                 allqueue(REDRAWBUTSOBJECT, 0);
1704                 break;
1705         case B_DUPLI_VERTS:
1706                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
1707                 DAG_scene_sort(G.scene);
1708                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1709                 allqueue(REDRAWVIEW3D, 0);
1710                 allqueue(REDRAWBUTSOBJECT, 0);
1711                 break;
1712         case B_DUPLI_FACES:
1713                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
1714                 allqueue(REDRAWVIEW3D, 0);
1715                 allqueue(REDRAWBUTSOBJECT, 0);
1716                 break;
1717         case B_DUPLI_GROUP:
1718                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
1719                 allqueue(REDRAWVIEW3D, 0);
1720                 allqueue(REDRAWBUTSOBJECT, 0);
1721                 break;
1722                 
1723         case B_PRINTSPEED:
1724                 {
1725                         float vec[3];
1726                         CFRA++;
1727                         do_ob_ipo(ob);
1728                         where_is_object(ob);
1729                         VECCOPY(vec, ob->obmat[3]);
1730                         CFRA--;
1731                         do_ob_ipo(ob);
1732                         where_is_object(ob);
1733                         VecSubf(vec, vec, ob->obmat[3]);
1734                         prspeed= Normalize(vec);
1735                         scrarea_queue_winredraw(curarea);
1736                 }
1737                 break;
1738         case B_PRINTLEN:
1739                 if(ob->type==OB_CURVE) {
1740                         Curve *cu=ob->data;
1741                         
1742                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
1743                         scrarea_queue_winredraw(curarea);
1744                 } 
1745                 break;
1746         case B_RELKEY:
1747                 allspace(REMAKEIPO, 0);
1748                 allqueue(REDRAWBUTSOBJECT, 0);
1749                 allqueue(REDRAWBUTSEDIT, 0);
1750                 allqueue(REDRAWIPO, 0);
1751                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1752                 break;
1753         case B_CURVECHECK:
1754                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1755                 allqueue(REDRAWVIEW3D, 0);
1756                 break;
1757         
1758         case B_SOFTBODY_CHANGE:
1759                 ob->softflag |= OB_SB_REDO;
1760                 allqueue(REDRAWBUTSOBJECT, 0);
1761                 allqueue(REDRAWVIEW3D, 0);
1762                 break;
1763         case B_SOFTBODY_DEL_VG:
1764                 if(ob->soft) {
1765                         ob->soft->vertgroup= 0;
1766                         ob->softflag |= OB_SB_REDO;
1767                         allqueue(REDRAWBUTSOBJECT, 0);
1768                         allqueue(REDRAWVIEW3D, 0);
1769                 }
1770                 break;
1771         case B_SOFTBODY_BAKE:
1772                 if(ob->soft) softbody_bake(ob);
1773                 break;
1774         case B_SOFTBODY_BAKE_FREE:
1775                 if(ob->soft) sbObjectToSoftbody(ob);
1776                 allqueue(REDRAWBUTSOBJECT, 0);
1777                 allqueue(REDRAWVIEW3D, 0);
1778                 break;
1779         case B_FLUIDSIM_BAKE:
1780                 /* write config files (currently no simulation) */
1781                 fluidsimBake(ob);
1782                 break;
1783         case B_FLUIDSIM_MAKEPART:
1784                 {
1785                         PartEff *paf= NULL;
1786                         /* prepare fluidsim particle display */
1787                         // simplified delete effect, create new - recalc some particles...
1788                         if(ob==NULL || ob->type!=OB_MESH) break;
1789                         ob->fluidsimSettings->type = 0;
1790                         // reset type, and init particle system once normally
1791                         paf= give_parteff(ob); 
1792                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
1793                             (!paf)) { 
1794                                 // create new entry
1795                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
1796                         paf = give_parteff(ob);
1797                         if(paf) {
1798                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
1799                                 build_particle_system(ob);
1800                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
1801                         }
1802                 }
1803                 allqueue(REDRAWVIEW3D, 0);
1804                 allqueue(REDRAWBUTSOBJECT, 0);
1805                 break;
1806         case B_FLUIDSIM_SELDIR: 
1807                 {
1808                         ScrArea *sa = closest_bigger_area();
1809                         /* choose dir for surface files */
1810                         areawinset(sa->win);
1811                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
1812                 }
1813                 break;
1814         case B_FLUIDSIM_FORCEREDRAW:
1815                 /* force redraw */
1816                 allqueue(REDRAWBUTSOBJECT, 0);
1817                 allqueue(REDRAWVIEW3D, 0);
1818                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1819                 break;
1820         case B_GROUP_RELINK:
1821                 group_relink_nla_objects(ob);
1822                 allqueue(REDRAWVIEW3D, 0);
1823                 break;
1824                 
1825         default:
1826                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1827                         int a=B_SELEFFECT;
1828                         
1829                         eff= ob->effect.first;
1830                         while(eff) {
1831                                 if(event==a) eff->flag |= SELECT;
1832                                 else eff->flag &= ~SELECT;
1833                                 
1834                                 a++;
1835                                 eff= eff->next;
1836                         }
1837                         allqueue(REDRAWBUTSOBJECT, 0);
1838                 }
1839         }
1840
1841 }
1842
1843 static void do_add_groupmenu(void *arg, int event)
1844 {
1845         Object *ob= OBACT;
1846         
1847         if(ob) {
1848                 
1849                 if(event== -1) {
1850                         Group *group= add_group( "Group" );
1851                         add_to_group(group, ob);
1852                 }
1853                 else
1854                         add_to_group(BLI_findlink(&G.main->group, event), ob);
1855                         
1856                 ob->flag |= OB_FROMGROUP;
1857                 BASACT->flag |= OB_FROMGROUP;
1858                 allqueue(REDRAWBUTSOBJECT, 0);
1859                 allqueue(REDRAWVIEW3D, 0);
1860         }               
1861 }
1862
1863 static uiBlock *add_groupmenu(void *arg_unused)
1864 {
1865         uiBlock *block;
1866         Group *group;
1867         short yco= 0;
1868         char str[32];
1869         
1870         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1871         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1872
1873         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1874         for(group= G.main->group.first; group; group= group->id.next, yco++) {
1875                 if(group->id.lib) strcpy(str, "L  ");
1876                 else strcpy(str, "   ");
1877                 strcat(str, group->id.name+2);
1878                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
1879         }
1880         
1881         uiTextBoundsBlock(block, 50);
1882         uiBlockSetDirection(block, UI_DOWN);    
1883         
1884         return block;
1885 }
1886
1887 static void group_ob_rem(void *gr_v, void *ob_v)
1888 {
1889         Object *ob= OBACT;
1890         
1891         rem_from_group(gr_v, ob);
1892         if(find_group(ob)==NULL) {
1893                 ob->flag &= ~OB_FROMGROUP;
1894                 BASACT->flag &= ~OB_FROMGROUP;
1895         }
1896         allqueue(REDRAWBUTSOBJECT, 0);
1897         allqueue(REDRAWVIEW3D, 0);
1898
1899 }
1900
1901 static void group_local(void *gr_v, void *unused)
1902 {
1903         Group *group= gr_v;
1904         
1905         group->id.lib= NULL;
1906         
1907         allqueue(REDRAWBUTSOBJECT, 0);
1908         allqueue(REDRAWVIEW3D, 0);
1909         
1910 }
1911
1912 static void object_panel_object(Object *ob)
1913 {
1914         uiBlock *block;
1915         uiBut *but;
1916         Group *group;
1917         int a, xco, yco=0;
1918         short dx= 33, dy= 30;
1919
1920         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
1921         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
1922         
1923         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
1924         
1925         /* object name */
1926         uiBlockSetCol(block, TH_BUT_SETTING2);
1927         xco= std_libbuttons(block, 10, 180, 0, NULL, 0, ID_OB, 0, &ob->id, NULL, &(G.buts->menunr), B_OBALONE, B_OBLOCAL, 0, 0, B_KEEPDATA);
1928         uiBlockSetCol(block, TH_AUTO);
1929         
1930         /* parent */
1931         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
1932         
1933         /* TODO, check for ob->id.lib */
1934         but = uiDefButS(block, NUM, B_NOP, "PassIndex:",                xco+5, 150, 305-xco, 20, &ob->index, 0.0, 1000.0, 0, 0, "Index # for the IndexOB render pass.");
1935
1936         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1937
1938         /* all groups */
1939         for(group= G.main->group.first; group; group= group->id.next) {
1940                 if(object_in_group(ob, group)) {
1941                         xco= 160;
1942                         
1943                         uiBlockBeginAlign(block);
1944                         but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 150, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1945                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1946                         
1947                         if(group->id.lib) {
1948                                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 160, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
1949                                 uiButSetFunc(but, group_local, group, NULL);
1950                                 xco= 180;
1951                         }
1952                         but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
1953                         uiButSetFunc(but, group_ob_rem, group, ob);
1954                         
1955                         yco+= 20;
1956                         xco= 10;
1957                         
1958                         /* layers */
1959                         uiBlockBeginAlign(block);
1960                         for(a=0; a<5; a++)
1961                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1962                         for(a=0; a<5; a++)
1963                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1964                         
1965                         xco+= 7;
1966                         uiBlockBeginAlign(block);
1967                         for(a=5; a<10; a++)
1968                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1969                         for(a=5; a<10; a++)
1970                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1971                         
1972                         uiBlockEndAlign(block);
1973                         
1974                         yco+= 40;
1975                 }
1976         }
1977         
1978         if(120-yco < -10)
1979                 uiNewPanelHeight(block, 204 - (120-yco));
1980 }
1981
1982 static void object_panel_anim(Object *ob)
1983 {
1984         uiBlock *block;
1985         char str[32];
1986         
1987         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1988         if(uiNewPanel(curarea, block, "Anim settings", "Object", 320, 0, 318, 204)==0) return;
1989         
1990         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
1991         
1992         uiBlockBeginAlign(block);
1993         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");
1994         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");
1995         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");
1996         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");
1997         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");
1998         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");
1999         uiBlockBeginAlign(block);
2000         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,180,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
2001         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,180,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
2002         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,180,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
2003         
2004         uiBlockBeginAlign(block);
2005         uiDefButBitS(block, TOG, OB_DRAWKEY, REDRAWVIEW3D, "Draw Key",          24,155,71,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
2006         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");
2007         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,155,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
2008         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,155,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
2009         uiBlockBeginAlign(block);
2010         
2011         uiDefButBitS(block, TOG, OB_DUPLIFRAMES, B_DUPLI_FRAME, "DupliFrames",  24,130,95,20, &ob->transflag, 0, 0, 0, 0, "Make copy of object for every frame");
2012         uiDefButBitS(block, TOG, OB_DUPLIVERTS, B_DUPLI_VERTS, "DupliVerts",            119,130,95,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all vertices");
2013         uiDefButBitS(block, TOG, OB_DUPLIFACES, B_DUPLI_FACES, "DupliFaces",            214,130,102,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all faces");
2014         uiDefButBitS(block, TOG, OB_DUPLIGROUP, B_DUPLI_GROUP, "DupliGroup",            24,110,150,20, &ob->transflag, 0, 0, 0, 0, "Enable group instancing");
2015         if(ob->transflag & OB_DUPLIFRAMES)
2016                 uiDefButBitS(block, TOG, OB_DUPLINOSPEED, REDRAWVIEW3D, "No Speed",             174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Set dupliframes to still, regardless of frame");
2017         else if(ob->transflag & OB_DUPLIVERTS)
2018                 uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",                              174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to vertex normal");
2019         else if(ob->transflag & OB_DUPLIFACES)
2020                 uiDefButBitS(block, TOG, OB_DUPLIFACES_SCALE, REDRAWVIEW3D, "Scale",                    174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Scale dupli based on face size");
2021         else
2022                 uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_GROUP_RELINK, "GR:", 174,110,142,20, &ob->dup_group, "Instance an existing group");
2023
2024         uiBlockBeginAlign(block);
2025         /* DupSta and DupEnd are both shorts, so the maxframe is greater then their range
2026         just limit the buttons to the max short */
2027         uiDefButI(block, NUM, REDRAWVIEW3D, "DupSta:",          24,85,141,19, &ob->dupsta, 1.0, 32767, 0, 0, "Specify startframe for Dupliframes");
2028         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOn:",           170,85,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "Specify the number of frames to use between DupOff frames");
2029         uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
2030         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOff",           171,65,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "Specify recurring frames to exclude from the Dupliframes");
2031         uiBlockBeginAlign(block);
2032         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
2033         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");
2034         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");
2035         
2036         uiBlockBeginAlign(block);
2037         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
2038         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,10,104,20, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
2039         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,10,67,20, 0, 0, 0, 0, 0, "Print objectspeed");
2040         uiBlockEndAlign(block);
2041         
2042         sprintf(str, "%.4f", prspeed);
2043         uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
2044         
2045 }
2046
2047 static void object_panel_draw(Object *ob)
2048 {
2049         uiBlock *block;
2050         int xco, a, dx, dy;
2051         
2052         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
2053         if(uiNewPanel(curarea, block, "Draw", "Object", 640, 0, 318, 204)==0) return;
2054         
2055         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2056         
2057         /* LAYERS */
2058         xco= 120;
2059         dx= 35;
2060         dy= 30;
2061         
2062         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2063         
2064         uiBlockBeginAlign(block);
2065         for(a=0; a<5; a++)
2066                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2067         for(a=0; a<5; a++)
2068                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2069         
2070         xco+= 7;
2071         uiBlockBeginAlign(block);
2072         for(a=5; a<10; a++)
2073                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2074         for(a=5; a<10; a++)
2075                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2076         
2077         uiBlockEndAlign(block);
2078         
2079         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
2080         
2081         uiBlockBeginAlign(block);
2082         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
2083         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
2084         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
2085         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
2086         uiBlockEndAlign(block);
2087         
2088         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
2089         
2090         uiBlockBeginAlign(block);
2091         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
2092         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
2093         
2094         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
2095                           120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2096         uiDefButBitC(block, TOG, OB_AXIS, REDRAWVIEW3D, "Axis",                 210, 80, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's center and axis");
2097         
2098         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
2099         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");
2100         
2101         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)");
2102         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");
2103         
2104 }
2105
2106 void object_panel_constraint(char *context)
2107 {
2108         uiBlock *block;
2109         Object *ob= OBACT;
2110         ListBase *conlist;
2111         bConstraint *curcon;
2112         short xco, yco;
2113         char str[64];
2114         
2115         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
2116         if(uiNewPanel(curarea, block, "Constraints", context, 960, 0, 318, 204)==0) return;
2117         
2118         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2119         
2120         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2121         /* so first we make it default height */
2122         uiNewPanelHeight(block, 204);
2123         
2124         if(G.obedit==OBACT) return;     // ??
2125         
2126         conlist = get_active_constraints(OBACT);
2127         
2128         if (conlist) {
2129                 
2130                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint", 0, 190, 130, 20, "Add a new constraint");
2131                 
2132                 /* print active object or bone */
2133                 str[0]= 0;
2134                 if (ob->flag & OB_POSEMODE){
2135                         bPoseChannel *pchan= get_active_posechannel(ob);
2136                         if(pchan) sprintf(str, "To Bone: %s", pchan->name);
2137                 }
2138                 else {
2139                         sprintf(str, "To Object: %s", ob->id.name+2);
2140                 }
2141                 uiDefBut(block, LABEL, 1, str,  150, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Displays Active Object or Bone name");
2142                 
2143                 /* Go through the list of constraints and draw them */
2144                 xco = 10;
2145                 yco = 160;
2146                 
2147                 for (curcon = conlist->first; curcon; curcon=curcon->next) {
2148                         /* hrms, the temporal constraint should not draw! */
2149                         if(curcon->type==CONSTRAINT_TYPE_KINEMATIC) {
2150                                 bKinematicConstraint *data= curcon->data;
2151                                 if(data->flag & CONSTRAINT_IK_TEMP)
2152                                         continue;
2153                         }
2154                         /* Draw default constraint header */
2155                         draw_constraint(block, conlist, curcon, &xco, &yco);    
2156                 }
2157                 
2158                 if(yco < 0) uiNewPanelHeight(block, 204-yco);
2159                 
2160         }
2161 }
2162
2163 void do_effects_panels(unsigned short event)
2164 {
2165         Object *ob;
2166         Base *base;
2167         Effect *eff, *effn;
2168         PartEff *paf;
2169         
2170         ob= OBACT;
2171
2172         switch(event) {
2173
2174     case B_AUTOTIMEOFS:
2175                 auto_timeoffs();
2176                 break;
2177         case B_FRAMEMAP:
2178                 G.scene->r.framelen= G.scene->r.framapto;
2179                 G.scene->r.framelen/= G.scene->r.images;
2180                 allqueue(REDRAWALL, 0);
2181                 break;
2182         case B_NEWEFFECT:
2183                 if(ob) {
2184                         if(ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) { 
2185                                 // NT particles and fluid meshes currently dont work together -> switch off beforehand
2186                                 if(ob->fluidsimSettings->type == OB_FLUIDSIM_DOMAIN) {
2187                                         pupmenu("Fluidsim Particle Error%t|Please disable the fluidsim domain before activating particles.%x0");
2188                                         break;
2189                                         //ob->fluidsimFlag = 0; ob->fluidsimSettings->type = 0; allqueue(REDRAWVIEW3D, 0); 
2190                                 }
2191                         }
2192                         if (BLI_countlist(&ob->effect)==MAX_EFFECT)
2193                                 error("Unable to add: effect limit reached");
2194                         else
2195                                 copy_act_effect(ob);
2196                 }
2197                 DAG_scene_sort(G.scene);
2198                 BIF_undo_push("New effect");
2199                 allqueue(REDRAWBUTSOBJECT, 0);
2200                 break;
2201         case B_DELEFFECT:
2202                 if(ob==NULL || ob->type!=OB_MESH) break;
2203                 eff= ob->effect.first;
2204                 while(eff) {
2205                         effn= eff->next;
2206                         if(eff->flag & SELECT) {
2207                                 BLI_remlink(&ob->effect, eff);
2208                                 free_effect(eff);
2209                                 break;
2210                         }
2211                         eff= effn;
2212                 }
2213                 BIF_undo_push("Delete effect");
2214                 allqueue(REDRAWVIEW3D, 0);
2215                 allqueue(REDRAWBUTSOBJECT, 0);
2216                 break;
2217         case B_NEXTEFFECT:
2218                 if(ob==0 || ob->type!=OB_MESH) break;
2219                 eff= ob->effect.first;
2220                 while(eff) {
2221                         if(eff->flag & SELECT) {
2222                                 if(eff->next) {
2223                                         eff->flag &= ~SELECT;
2224                                         eff->next->flag |= SELECT;
2225                                 }
2226                                 break;
2227                         }
2228                         eff= eff->next;
2229                 }
2230                 allqueue(REDRAWBUTSOBJECT, 0);
2231                 break;
2232         case B_PREVEFFECT:
2233                 if(ob==0 || ob->type!=OB_MESH) break;
2234                 eff= ob->effect.first;
2235                 while(eff) {
2236                         if(eff->flag & SELECT) {
2237                                 if(eff->prev) {
2238                                         eff->flag &= ~SELECT;
2239                                         eff->prev->flag |= SELECT;
2240                                 }
2241                                 break;
2242                         }
2243                         eff= eff->next;
2244                 }
2245                 allqueue(REDRAWBUTSOBJECT, 0);
2246                 break;
2247         case B_EFFECT_DEP:
2248                 DAG_scene_sort(G.scene);
2249                 /* no break, pass on */
2250         case B_CALCEFFECT:
2251                 if(ob==NULL || ob->type!=OB_MESH) break;
2252                 eff= ob->effect.first;
2253                 while(eff) {
2254                         if(eff->flag & SELECT) {
2255                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2256                         }
2257                         eff= eff->next;
2258                 }
2259                 allqueue(REDRAWVIEW3D, 0);
2260                 allqueue(REDRAWBUTSOBJECT, 0);
2261                 break;
2262         case B_PAF_SET_VG:
2263                 
2264                 paf= give_parteff(ob);
2265                 if(paf) {
2266                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname);
2267                         if(dg)
2268                                 paf->vertgroup= get_defgroup_num(ob, dg)+1;
2269                         else
2270                                 paf->vertgroup= 0;
2271                         
2272                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2273                         allqueue(REDRAWVIEW3D, 0);
2274                 }
2275                 break;
2276         case B_PAF_SET_VG1:
2277                 
2278                 paf= give_parteff(ob);
2279                 if(paf) {
2280                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname_v);
2281                         if(dg)
2282                                 paf->vertgroup_v= get_defgroup_num(ob, dg)+1;
2283                         else
2284                                 paf->vertgroup_v= 0;
2285                         
2286                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2287                         allqueue(REDRAWVIEW3D, 0);
2288                 }
2289                 break;
2290         case B_FIELD_DEP:
2291                 /* do this before scene sort, that one checks for CU_PATH */
2292                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE) {
2293                         Curve *cu= ob->data;
2294                         
2295                         cu->flag |= (CU_PATH|CU_3D);
2296                         do_curvebuts(B_CU3D);   /* all curves too */
2297                 }
2298                 DAG_scene_sort(G.scene);
2299
2300                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE)
2301                         DAG_object_flush_update(G.scene, ob, OB_RECALC);
2302                 else
2303                         DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2304
2305                 allqueue(REDRAWVIEW3D, 0);
2306                 allqueue(REDRAWBUTSOBJECT, 0);
2307                 break;
2308         case B_FIELD_CHANGE:
2309                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2310                 allqueue(REDRAWVIEW3D, 0);
2311                 break;
2312         case B_RECALCAL:
2313                 if (G.vd==NULL)
2314                         break;
2315                 
2316                 base= FIRSTBASE;
2317                 while(base) {
2318                         if(base->lay & G.vd->lay) {
2319                                 ob= base->object;
2320                                 eff= ob->effect.first;
2321                                 while(eff) {
2322                                         if(eff->flag & SELECT) {
2323                                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2324                                         }
2325                                         eff= eff->next;
2326                                 }
2327                         }
2328                         base= base->next;
2329                 }
2330                 allqueue(REDRAWVIEW3D, 0);
2331                 break;
2332         default:
2333                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2334                         ob= OBACT;
2335                         if(ob) {
2336                                 int a=B_SELEFFECT;
2337                                 
2338                                 eff= ob->effect.first;
2339                                 while(eff) {
2340                                         if(event==a) eff->flag |= SELECT;
2341                                         else eff->flag &= ~SELECT;
2342                                         
2343                                         a++;
2344                                         eff= eff->next;
2345                                 }
2346                                 allqueue(REDRAWBUTSOBJECT, 0);
2347                         }
2348                 }
2349         }
2350
2351 }
2352
2353 /* Panel for particle interaction settings */
2354 static void object_panel_fields(Object *ob)
2355 {
2356         uiBlock *block;
2357
2358         block= uiNewBlock(&curarea->uiblocks, "object_panel_fields", UI_EMBOSS, UI_HELV, curarea->win);
2359         if(uiNewPanel(curarea, block, "Fields and Deflection", "Physics", 0, 0, 318, 204)==0) return;
2360
2361         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2362         
2363         /* should become button, option? */
2364         if(ob->pd==NULL) {
2365                 ob->pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
2366                 /* and if needed, init here */
2367                 ob->pd->pdef_sbdamp = 0.1f;
2368                 ob->pd->pdef_sbift  = 0.2f;
2369                 ob->pd->pdef_sboft  = 0.02f;
2370         }
2371         
2372         if(ob->pd) {
2373                 PartDeflect *pd= ob->pd;
2374                 char *menustr= MEM_mallocN(256, "temp string");
2375                 char *tipstr="Choose field type";
2376                 
2377                 uiDefBut(block, LABEL, 0, "Fields",             10,180,140,20, NULL, 0.0, 0, 0, 0, "");
2378                 
2379                 /* setup menu button */
2380                 sprintf(menustr, "Field Type%%t|None %%x0|Spherical %%x%d|Wind %%x%d|Vortex %%x%d|Curve Guide %%x%d", 
2381                                 PFIELD_FORCE, PFIELD_WIND, PFIELD_VORTEX, PFIELD_GUIDE);
2382                 
2383                 if(pd->forcefield==PFIELD_FORCE) tipstr= "Object center attracts or repels particles";
2384                 else if(pd->forcefield==PFIELD_WIND) tipstr= "Constant force applied in direction of Object Z axis";
2385                 else if(pd->forcefield==PFIELD_VORTEX) tipstr= "Particles swirl around Z-axis of the Object";
2386                 else if(pd->forcefield==PFIELD_GUIDE) tipstr= "Use a Curve Path to guide particles";
2387                 
2388                 uiDefButS(block, MENU, B_FIELD_DEP, menustr,                    10,160,140,20, &pd->forcefield, 0.0, 0.0, 0, 0, tipstr);
2389                 MEM_freeN(menustr);
2390                 
2391                 if(pd->forcefield) {
2392                         uiBlockBeginAlign(block);
2393                         if(pd->forcefield == PFIELD_GUIDE) {
2394                                 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.");
2395                                 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");
2396                         }
2397                         else {  
2398                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Strength: ",     10,110,140,20, &pd->f_strength, -1000, 1000, 10, 0, "Strength of force field");
2399                                 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)");
2400                         }
2401                         
2402                         uiBlockBeginAlign(block);
2403                         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");
2404                         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");
2405                         uiBlockEndAlign(block);
2406                         
2407                         if(pd->forcefield == PFIELD_GUIDE)
2408                                 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");
2409                         
2410                 }
2411                 
2412                 uiDefBut(block, LABEL, 0, "Deflection", 160,180,140,20, NULL, 0.0, 0, 0, 0, "");
2413                         
2414                 /* only meshes collide now */
2415                 if(ob->type==OB_MESH) {
2416                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision");
2417                         if(pd->deflect) {
2418                                 uiDefBut(block, LABEL, 0, "Particles",                  160,140,150,20, NULL, 0.0, 0, 0, 0, "");
2419                                 
2420                                 uiBlockBeginAlign(block);
2421                                 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");
2422                                 uiDefButF(block, NUM, B_DIFF, "Rnd Damping: ",  160,100,150,20, &pd->pdef_rdamp, 0.0, 1.0, 10, 0, "Random variation of damping");
2423                                 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");
2424                                 uiBlockEndAlign(block);
2425                                 
2426                                 uiDefBut(block, LABEL, 0, "Soft Body",                  160,60,150,20, NULL, 0.0, 0, 0, 0, "");
2427
2428                                 uiBlockBeginAlign(block);
2429                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Damping:",       160,40,150,20, &pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2430                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,20,150,20, &pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2431                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160, 0,150,20, &pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2432                         }
2433                 }               
2434         }
2435 }
2436
2437
2438 /* Panel for softbodies */
2439 static void object_softbodies__enable(void *ob_v, void *arg2)
2440 {
2441         Object *ob = ob_v;
2442         ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody);
2443
2444         if (modifiers_isSoftbodyEnabled(ob)) {
2445                 if (md) {
2446                         md->mode &= ~(eModifierMode_Render|eModifierMode_Realtime);
2447                 }
2448         } else {
2449                 if (!md) {
2450                         md = modifier_new(eModifierType_Softbody);
2451                         BLI_addhead(&ob->modifiers, md);
2452                 }
2453
2454                 md->mode |= eModifierMode_Render|eModifierMode_Realtime;
2455
2456                 if (!ob->soft) {
2457                         ob->soft= sbNew();
2458                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2459                 }
2460         }
2461
2462         allqueue(REDRAWBUTSEDIT, 0);
2463 }
2464
2465 static int _can_softbodies_at_all(Object *ob)
2466 {
2467         // list of Yes
2468     if ((ob->type==OB_MESH)
2469                 || (ob->type==OB_CURVE)
2470                 || (ob->type==OB_LATTICE)
2471                 || (ob->type==OB_SURF)
2472                 ) return 1;
2473         // else deny
2474         return 0;
2475 }
2476 static void object_softbodies_II(Object *ob)
2477 {
2478         uiBlock *block;
2479         static int val;
2480     if(!_can_softbodies_at_all(ob)) return;
2481         block= uiNewBlock(&curarea->uiblocks, "object_softbodies_II", UI_EMBOSS, UI_HELV, curarea->win);
2482         uiNewPanelTabbed("Soft Body", "Physics");
2483         if(uiNewPanel(curarea, block, "Soft Body Collision", "Physics", 651, 0, 318, 204)==0) return;
2484
2485         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2486
2487         val = modifiers_isSoftbodyEnabled(ob);
2488         if(!val) {
2489                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2490                 uiBlockBeginAlign(block);
2491                 uiDefBut(block, LABEL, 0, "Object is not a softbody",10,190,300,20, NULL, 0.0, 0, 0, 0, ""); 
2492                 uiDefBut(block, LABEL, 0, "However it can deflect a softbody",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2493                 /* OTHER OBJECTS COLLISION STUFF */
2494                 if (ob->type==OB_MESH){
2495                         uiBlockBeginAlign(block);
2496                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",10,50,150,20, &ob->pd->deflect, 0, 0, 0, 0, "Makes this object visible to softbody objects");
2497                         if(ob->pd->deflect) {
2498                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Damping:",       160,50,150,20, &ob->pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2499                             uiDefButBitS(block, TOG,OB_SB_COLLFINAL , B_DIFF, "Ev.M.Stack",10,30,150,20, &ob->softflag, 0, 0, 0, 0, "Pick collision object from modifier stack");
2500                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2501                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2502                         }
2503                 }
2504                 uiBlockEndAlign(block);
2505         }
2506         else{
2507                 SoftBody *sb= ob->soft;
2508                 /* SELF COLLISION STUFF */
2509                 if ((ob->type==OB_MESH)||(ob->type==OB_CURVE) ) {
2510                         uiBlockBeginAlign(block);
2511                         if (ob->softflag & OB_SB_EDGES){
2512                                 uiDefButBitS(block, TOG, OB_SB_SELF, B_SOFTBODY_CHANGE, "Self Collision",               10,170,150,20, &ob->softflag, 0, 0, 0, 0, "enable naive vertex ball self collision");
2513                                 if(ob->softflag & OB_SB_SELF){
2514                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Ball Size:", 160,170,150,20, &sb->colball, -10.0,  10.0, 10, 0, "Absolute ball size or factor if not manual adjusted");
2515                                         uiDefButS(block, ROW, B_DIFF, "Man",10,150,60,20, &sb->sbc_mode, 4.0,(float)0, 0, 0, "Manual adjust");
2516                                         uiDefButS(block, ROW, B_DIFF, "Av",70,150,60,20, &sb->sbc_mode, 4.0,(float)1, 0, 0, "Average Spring lenght * Ball Size");
2517                                         uiDefButS(block, ROW, B_DIFF, "Min",130,150,60,20, &sb->sbc_mode, 4.0,(float)2, 0, 0, "Minimal Spring lenght * Ball Size");
2518                                         uiDefButS(block, ROW, B_DIFF, "Max",190,150,60,20, &sb->sbc_mode, 4.0,(float)3, 0, 0, "Maximal Spring lenght * Ball Size");
2519                                         uiDefButS(block, ROW, B_DIFF, "AvMiMa",250,150,60,20, &sb->sbc_mode, 4.0,(float)4, 0, 0, "(Min+Max)/2 * Ball Size");
2520                                         uiDefButF(block, NUM, B_DIFF, "B Stiff:", 10,130,150,20, &sb->ballstiff, 0.001,  100.0, 10, 0, "Ball inflating presure");
2521                                         uiDefButF(block, NUM, B_DIFF, "B Damp:", 160,130,150,20, &sb->balldamp,  0.001,  1.0, 10, 0, "Blending to inelastic collision");
2522                                 }
2523                         }
2524                         else{
2525                                 uiDefBut(block, LABEL, 0, "<Self Collision> not available because there",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2526                                 uiDefBut(block, LABEL, 0, "are no edges, enable <Use Edges>",10,150,300,20, NULL, 0.0, 0, 0, 0, ""); 
2527                         }
2528
2529                         uiBlockEndAlign(block);
2530                         /*SOLVER SETTINGS*/
2531                         uiDefButF(block, NUM, B_DIFF, "Error Lim:",     10,100,130,20, &sb->rklimit , 0.001, 10.0, 10, 0, "The Runge-Kutta ODE solver error limit, low value gives more precision, high values speed");
2532                         uiDefButBitS(block, TOG, SBSO_OLDERR, B_DIFF,"O", 140,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Old Error Calculation");
2533                         uiDefButS(block, NUM, B_DIFF, "Fuzzy:", 160,100,130,20, &sb->fuzzyness,  1.00,  100.0, 10, 0, "Fuzzyness while on collision, high values make collsion handling faster but less stable");
2534                         uiDefButBitS(block, TOG, SBSO_MONITOR, B_DIFF,"M", 290,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Turn on SB diagnose console prints");
2535                         uiDefButS(block, NUM, B_DIFF, "MinS:", 10,80,100,20, &sb->minloops,  0.00,  30000.0, 10, 0, "Minimal # solver steps/frame ");
2536                         uiDefButS(block, NUM, B_DIFF, "MaxS:", 110,80,100,20, &sb->maxloops,  0.00,  30000.0, 10, 0, "Maximal # solver steps/frame ");
2537                         uiDefButS(block, NUM, B_DIFF, "Choke:", 210,80,100,20, &sb->choke, 0.00,  100.0, 10, 0, "'Viscosity' inside collision target ");
2538                 }
2539                 /* OTHER OBJECTS COLLISION STUFF */
2540                 if (ob->type==OB_MESH){
2541                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",10,50,150,20, &ob->pd->deflect, 0, 0, 0, 0, "Makes this object visible to other softbody objects");
2542                         if(ob->pd->deflect) {
2543                                 uiDefButF(block, NUM, B_DIFF, "Damping:",       160,50,150,20, &ob->pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2544                             uiDefButBitS(block, TOG,OB_SB_COLLFINAL , B_DIFF, "Ev.M.Stack",10,30,150,20, &ob->softflag, 0, 0, 0, 0, "Pick collision object from modifier stack");
2545                                 uiDefButF(block, NUM, B_DIFF, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2546                                 uiDefButF(block, NUM, B_DIFF, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2547                         }
2548                 }
2549                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2550         }
2551         uiBlockEndAlign(block);
2552 }
2553
2554 static void object_softbodies(Object *ob)
2555 {
2556         uiBlock *block;
2557         static int val;
2558         uiBut *but;
2559     if(!_can_softbodies_at_all(ob)) return;
2560         block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
2561         if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
2562         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2563
2564         val = modifiers_isSoftbodyEnabled(ob);
2565         but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Soft Body",      10,200,130,20, &val, 0, 0, 0, 0, "Sets object to become soft body");
2566         uiButSetFunc(but, object_softbodies__enable, ob, NULL);
2567         uiDefBut(block, LABEL, 0, "",10,10,300,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2568
2569         if(modifiers_isSoftbodyEnabled(ob)){
2570                 SoftBody *sb= ob->soft;
2571                 int defCount;
2572                 char *menustr;
2573
2574                 if(sb==NULL) {
2575                         sb= ob->soft= sbNew();
2576                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2577                 }
2578
2579                 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");
2580
2581                 if(sb->keys) uiSetButLock(1, "Soft Body is baked, free it first");
2582
2583                 if(ob->softflag & OB_SB_BAKESET) {
2584                         uiBlockBeginAlign(block);
2585                         uiDefButI(block, NUM, B_DIFF, "Start:",                 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking");
2586                         uiDefButI(block, NUM, B_DIFF, "End:",                   110, 170,100,20, &sb->efra, 1.0, 10000.0, 10, 0, "End frame for baking");
2587                         uiDefButI(block, NUM, B_DIFF, "Interval:",              210, 170,100,20, &sb->interval, 1.0, 10.0, 10, 0, "Interval in frames between baked keys");
2588                         uiBlockEndAlign(block);
2589
2590                         uiDefButS(block, TOG, B_DIFF, "Local",                  10, 145,100,20, &sb->local, 0.0, 0.0, 0, 0, "Use local coordinates for baking");
2591
2592
2593                         uiClearButLock();
2594                         uiBlockBeginAlign(block);
2595
2596                         if(sb->keys) {
2597                                 char str[128];
2598                                 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");
2599                                 sprintf(str, "Stored %d vertices %d keys %.3f MB", sb->totpoint, sb->totkey, ((float)16*sb->totpoint*sb->totkey)/(1024.0*1024.0));
2600                                 uiDefBut(block, LABEL, 0, str, 10, 100,300,20, NULL, 0.0, 0.0, 00, 0, "");
2601                         }
2602                         else                            
2603                                 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");
2604
2605                 }
2606                 else {
2607                         /* GENERAL STUFF */
2608                         static char str[128];
2609                         if (sb->totpoint){
2610                         sprintf(str, "Vertex Mass; Object mass %f [k]",sb->nodemass*sb->totpoint/1000.0f);
2611                         }
2612                         else{
2613                         sprintf(str, "Vertex Mass");
2614                         }
2615                         uiBlockBeginAlign(block);
2616                         uiDefButF(block, NUM, B_DIFF, "Friction:", 10, 170,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements");
2617                         uiDefButF(block, NUM, B_DIFF, "Mass:",     160, 170,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str);
2618                         uiDefButF(block, NUM, B_DIFF, "Grav:",     10,150,150,20, &sb->grav , 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
2619                         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");
2620                         uiBlockEndAlign(block);
2621
2622                         /* GOAL STUFF */
2623                         uiBlockBeginAlign(block);
2624                         uiDefButBitS(block, TOG, OB_SB_GOAL, B_SOFTBODY_CHANGE, "Use Goal",     10,120,130,20, &ob->softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
2625                         if (ob->softflag & OB_SB_GOAL){
2626                                 if(ob->type==OB_MESH) {
2627                                         menustr= get_vertexgroup_menustr(ob);
2628                                         defCount=BLI_countlist(&ob->defbase);
2629                                         if(defCount==0) sb->vertgroup= 0;
2630                                         uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr,      140,120,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
2631                                         MEM_freeN (menustr);
2632
2633                                         if(sb->vertgroup) {
2634                                                 bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
2635                                                 if(defGroup)
2636                                                         uiDefBut(block, BUT, B_DIFF, defGroup->name,    160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group");
2637                                                 else
2638                                                         uiDefBut(block, BUT, B_DIFF, "(no group)",      160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
2639                                                 uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,120,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
2640                                         }
2641                                         else
2642                                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
2643                                 }
2644                                 else {
2645                                         uiDefButS(block, TOG, B_SOFTBODY_CHANGE, "W",                   140,120,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
2646                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
2647                                 }
2648
2649                                 uiDefButF(block, NUM, B_DIFF, "G Stiff:",       10,100,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
2650                                 uiDefButF(block, NUM, B_DIFF, "G Damp:",        160,100,150,20, &sb->goalfrict  , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
2651                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Min:",              10,80,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
2652                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Max:",              160,80,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
2653                         }
2654                         uiBlockEndAlign(block);
2655
2656                         /* EDGE SPRING STUFF */
2657                         if(ob->type!=OB_SURF) {
2658                                 uiBlockBeginAlign(block);
2659                                 uiDefButBitS(block, TOG, OB_SB_EDGES, B_SOFTBODY_CHANGE, "Use Edges",           10,50,90,20, &ob->softflag, 0, 0, 0, 0, "Use Edges as springs");
2660                         if (ob->softflag & OB_SB_EDGES){
2661                                 uiDefButBitS(block, TOG, OB_SB_QUADS, B_SOFTBODY_CHANGE, "Stiff Quads",         110,50,90,20, &ob->softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
2662                                 uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_DIFF, "CEdge",               220,50,45,20, &ob->softflag, 0, 0, 0, 0, "Edge collide too"); 
2663                                 uiDefButBitS(block, TOG, OB_SB_FACECOLL, B_DIFF, "CFace",               265,50,45,20, &ob->softflag, 0, 0, 0, 0, "Faces collide too SLOOOOOW warning "); 
2664                                 uiDefButF(block, NUM, B_DIFF, "E Stiff:",       10,30,150,20, &sb->inspring, 0.0,  0.999, 10, 0, "Edge spring stiffness");
2665                                 uiDefButF(block, NUM, B_DIFF, "E Damp:",        160,30,150,20, &sb->infrict, 0.0,  50.0, 10, 0, "Edge spring friction");
2666                                 uiDefButS(block, NUM, B_DIFF, "Aero:",     10,10,150,20, &sb->aeroedge,  0.00,  30000.0, 10, 0, "Make edges 'sail'");
2667                                 if(ob->type==OB_MESH) {
2668                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Rigidity:", 160,10,150,20, &sb->secondspring, 0.0,  10.0, 10, 0, "Strenght of Springs over 2 Edges");
2669                                 }
2670                                 else sb->secondspring = 0;
2671                                 uiDefBut(block, LABEL, 0, "",10,10,1,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2672                         }
2673                                 uiBlockEndAlign(block);
2674                         }
2675                 }
2676         }
2677         uiBlockEndAlign(block);
2678 }
2679
2680 static void object_panel_particles_motion(Object *ob)
2681 {
2682         uiBlock *block;
2683         uiBut *but;
2684         PartEff *paf= give_parteff(ob);
2685
2686         if (paf==NULL) return;
2687                 
2688         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles_motion", UI_EMBOSS, UI_HELV, curarea->win);
2689         uiNewPanelTabbed("Particles ", "Physics");
2690         if(uiNewPanel(curarea, block, "Particle Motion", "Physics", 320, 0, 318, 204)==0) return;
2691         
2692         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2693         
2694         /* top row */
2695         uiBlockBeginAlign(block);
2696         uiDefButI(block, NUM, B_CALCEFFECT, "Keys:",    0,180,75,20, &paf->totkey, 1.0, 100.0, 0, 0, "Specify the number of key positions");
2697         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");
2698         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");
2699         uiDefButF(block, NUM, B_CALCEFFECT, "RLife:",   225,180,85,20, &paf->randlife, 0.0, 2.0, 10, 1, "Give the particlelife a random variation");
2700         uiBlockEndAlign(block);
2701         
2702         /* left collumn */
2703         uiDefBut(block, LABEL, 0, "Velocity:",                  0,160,150,20, NULL, 0.0, 0, 0, 0, "");
2704         uiBlockBeginAlign(block);
2705         uiBlockSetCol(block, TH_BUT_SETTING2);
2706         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");
2707         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");
2708         uiDefButF(block, NUM, B_CALCEFFECT, "Random:",          0,104,150,18, &paf->randfac, 0.0, 2.0, 1, 3, "Give the startingspeed a random variation");
2709         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");
2710         uiDefButF(block, NUM, B_CALCEFFECT, "Damping:",         0,68,150,18, &paf->damp, 0.0, 1.0, 1, 3, "Specify the damping factor");
2711         uiBlockSetCol(block, TH_AUTO);
2712         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");
2713         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)OBACT);
2714         uiBlockEndAlign(block);
2715         
2716         uiDefBut(block, LABEL, 0, "Texture Emission",                   0,30,150,20, NULL, 0.0, 0, 0, 0, "");
2717         uiBlockBeginAlign(block);
2718         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");
2719         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");
2720         
2721         /* right collumn */
2722         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_CALCEFFECT, "GR:", 160, 155, 150, 20, &paf->group, "Limit Force Fields to this Group"); 
2723
2724         uiBlockBeginAlign(block);
2725         uiDefBut(block, LABEL, 0, "Force:",                             160,130,75,20, NULL, 0.0, 0, 0, 0, "");
2726         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");
2727         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");
2728         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");
2729         
2730         uiBlockBeginAlign(block);
2731         uiDefButS(block, NUM, B_CALCEFFECT, "Tex:",             160,80,75,20, &paf->speedtex, 1.0, 10.0, 0, 2, "Specify the texture used for force");
2732         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");
2733         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");
2734         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");
2735         
2736         uiBlockBeginAlign(block);
2737         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");
2738         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");
2739         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");
2740         
2741         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");
2742         
2743 }
2744
2745
2746 static void object_panel_particles(Object *ob)
2747 {
2748         uiBlock *block;
2749         uiBut *but;
2750         PartEff *paf= give_parteff(ob);
2751         
2752         /* the panelname "Particles " has a space to exclude previous saved panel "Particles" */
2753         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles", UI_EMBOSS, UI_HELV, curarea->win);
2754         if(uiNewPanel(curarea, block, "Particles ", "Physics", 320, 0, 318, 204)==0) return;
2755
2756         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2757         
2758         if (ob->type == OB_MESH) {
2759                 uiBlockBeginAlign(block);
2760                 if(paf==NULL)
2761                         uiDefBut(block, BUT, B_NEWEFFECT, "NEW",        0,180,75,20, 0, 0, 0, 0, 0, "Create a new Particle effect");
2762                 else
2763                         uiDefBut(block, BUT, B_DELEFFECT, "Delete", 0,180,75,20, 0, 0, 0, 0, 0, "Delete the effect");
2764         }