Patch/Bugfix so wind noise got controlable seed and therefore redoable cloth sims...
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL 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.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <time.h>
31 #include <math.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include "MEM_guardedalloc.h"
40
41 #include "DNA_ID.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_space_types.h"
44 #include "DNA_scene_types.h"
45
46 #include "BKE_action.h"
47 #include "BKE_cloth.h"
48 #include "BKE_fluidsim.h"
49 #include "BKE_global.h"
50 #include "BKE_main.h"
51 #include "BKE_library.h"
52 #include "BKE_softbody.h"
53 #include "BKE_utildefines.h"
54 #include "BKE_particle.h"
55 #include "BKE_pointcache.h"
56
57 #include "BLI_blenlib.h"
58 #include "BLI_arithb.h"
59
60 #include "BSE_filesel.h"
61 #include "BSE_headerbuttons.h"
62
63 #include "BIF_butspace.h"
64 #include "BIF_editaction.h"
65 #include "BIF_editparticle.h"
66 #include "BIF_gl.h"
67 #include "BIF_glutil.h"
68 #include "BIF_graphics.h"
69 #include "BIF_interface.h"
70 #include "BIF_keyframing.h"
71 #include "BIF_keyval.h"
72 #include "BIF_mainqueue.h"
73 #include "BIF_mywindow.h"
74 #include "BIF_poseobject.h"
75 #include "BIF_resources.h"
76 #include "BIF_screen.h"
77 #include "BIF_space.h"
78 #include "BIF_toolbox.h"
79 #include "BIF_outliner.h"
80
81 #include "BDR_drawobject.h"
82 #include "BDR_editcurve.h"
83
84 #include "mydevice.h"
85 #include "blendef.h"
86
87 /* -----includes for this file specific----- */
88
89
90 #include "DNA_action_types.h"
91 #include "DNA_armature_types.h"
92 #include "DNA_camera_types.h"
93 #include "DNA_cloth_types.h"
94 #include "DNA_constraint_types.h"
95 #include "DNA_curve_types.h"
96 #include "DNA_effect_types.h"
97 #include "DNA_group_types.h"
98 #include "DNA_image_types.h"
99 #include "DNA_key_types.h"
100 #include "DNA_lamp_types.h"
101 #include "DNA_lattice_types.h"
102 #include "DNA_material_types.h"
103 #include "DNA_meta_types.h"
104 #include "DNA_mesh_types.h"
105 #include "DNA_modifier_types.h"
106 #include "DNA_object_types.h"
107 #include "DNA_object_force.h"
108 #include "DNA_object_fluidsim.h"
109 #include "DNA_particle_types.h"
110 #include "DNA_radio_types.h"
111 #include "DNA_screen_types.h"
112 #include "DNA_sound_types.h"
113 #include "DNA_texture_types.h"
114 #include "DNA_userdef_types.h"
115 #include "DNA_vfont_types.h"
116 #include "DNA_view3d_types.h"
117 #include "DNA_world_types.h"
118 #include "DNA_text_types.h"
119
120 #include "BKE_anim.h"
121 #include "BKE_armature.h"
122 #include "BKE_constraint.h"
123 #include "BKE_curve.h"
124 #include "BKE_deform.h"
125 #include "BKE_depsgraph.h"
126 #include "BKE_displist.h"
127 #include "BKE_effect.h"
128 #include "BKE_font.h"
129 #include "BKE_group.h"
130 #include "BKE_image.h"
131 #include "BKE_ipo.h"
132 #include "BKE_lattice.h"
133 #include "BKE_material.h"
134 #include "BKE_mball.h"
135 #include "BKE_mesh.h"
136 #include "BKE_modifier.h"
137 #include "BKE_object.h"
138 #include "BKE_particle.h"
139 #include "BKE_sound.h"
140 #include "BKE_texture.h"
141 #include "BKE_utildefines.h"
142 #include "BKE_DerivedMesh.h"
143
144 #include "LBM_fluidsim.h"
145 #include "elbeem.h"
146
147 #include "BIF_editconstraint.h"
148 #include "BIF_editdeform.h"
149 #include "BIF_editparticle.h"
150
151 #include "BSE_editipo.h"
152 #include "BSE_edit.h"
153
154 #include "BDR_editobject.h"
155
156 #ifndef DISABLE_PYTHON
157 #include "BPY_extern.h"
158 #endif
159
160 #include "butspace.h" // own module
161
162 #include "PIL_time.h"
163
164 static float prspeed=0.0;
165 float prlen=0.0;
166
167
168 /* ********************* CONSTRAINT ***************************** */
169
170 static void constraint_active_func(void *ob_v, void *con_v)
171 {
172         Object *ob= ob_v;
173         bConstraint *con;
174         ListBase *lb;
175         
176         /* lets be nice and escape if its active already */
177         if(con_v) {
178                 con= con_v;
179                 if(con->flag & CONSTRAINT_ACTIVE) return;
180         }
181         
182         lb= get_active_constraints(ob);
183         if (lb == NULL) return;
184         
185         for(con= lb->first; con; con= con->next) {
186                 if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
187                 else con->flag &= ~CONSTRAINT_ACTIVE;
188         }
189
190         /* make sure ipowin and buttons shows it */
191         if(ob->ipowin==ID_CO) {
192                 allqueue(REDRAWIPO, ID_CO);
193                 allspace(REMAKEIPO, 0);
194                 allqueue(REDRAWNLA, 0);
195         }
196         allqueue(REDRAWBUTSOBJECT, 0);
197 }
198
199 static void add_constraint_to_active(Object *ob, bConstraint *con)
200 {
201         ListBase *list= get_active_constraints(ob);
202         bPoseChannel *pchan= get_active_posechannel(ob);
203         
204         if (list) {
205                 unique_constraint_name(con, list);
206                 BLI_addtail(list, con);
207                 
208                 if (proxylocked_constraints_owner(ob, pchan))
209                         con->flag |= CONSTRAINT_PROXY_LOCAL;
210                 
211                 con->flag |= CONSTRAINT_ACTIVE;
212                 for (con= con->prev; con; con= con->prev)
213                         con->flag &= ~CONSTRAINT_ACTIVE;
214         }
215 }
216
217 /* returns base ID for Ipo, sets actname to channel if appropriate */
218 /* should not make action... */
219 static void get_constraint_ipo_context(void *ob_v, char *actname)
220 {
221         Object *ob= ob_v;
222         
223         /* todo: check object if it has ob-level action ipo */
224         if (ob->flag & OB_POSEMODE) {
225                 bPoseChannel *pchan;
226                 
227                 pchan = get_active_posechannel(ob);
228                 if (pchan) {
229                         BLI_strncpy(actname, pchan->name, 32);
230                 }
231         }
232         else if(ob->ipoflag & OB_ACTION_OB)
233                 strcpy(actname, "Object");
234 }       
235
236 /* initialize UI to show Ipo window and make sure channels etc exist */
237 static void enable_constraint_ipo_func (void *ob_v, void *con_v)
238 {
239         Object *ob= ob_v;
240         bConstraint *con = con_v;
241         char actname[32]="";
242         
243         /* verifies if active constraint is set and shown in UI */
244         constraint_active_func(ob_v, con_v);
245         
246         /* the context */
247         get_constraint_ipo_context(ob, actname);
248         
249         /* adds ipo & channels & curve if needed */
250         if(con->flag & CONSTRAINT_OWN_IPO)
251                 verify_ipo((ID *)ob, ID_CO, NULL, con->name, actname, 1);
252         else
253                 verify_ipo((ID *)ob, ID_CO, actname, con->name, NULL, 1);
254                 
255         /* make sure ipowin shows it */
256         ob->ipowin= ID_CO;
257         allqueue(REDRAWIPO, ID_CO);
258         allspace(REMAKEIPO, 0);
259         allqueue(REDRAWNLA, 0);
260 }
261
262
263 static void add_influence_key_to_constraint_func (void *ob_v, void *con_v)
264 {
265         Object *ob= ob_v;
266         bConstraint *con = con_v;
267         IpoCurve *icu;
268         char actname[32]="";
269         
270         /* verifies if active constraint is set and shown in UI */
271         constraint_active_func(ob_v, con_v);
272         
273         /* the context */
274         get_constraint_ipo_context(ob, actname);
275
276         /* adds ipo & channels & curve if needed */
277         if(con->flag & CONSTRAINT_OWN_IPO)
278                 icu= verify_ipocurve((ID *)ob, ID_CO, NULL, con->name, actname, CO_ENFORCE, 1);
279         else
280                 icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, NULL, CO_ENFORCE, 1);
281                 
282         if (!icu) {
283                 error("Cannot get a curve from this IPO, may be dealing with linked data");
284                 return;
285         }
286         
287         if(ob->action)
288                 insert_vert_icu(icu, get_action_frame(ob, (float)CFRA), con->enforce, 0);
289         else
290                 insert_vert_icu(icu, CFRA, con->enforce, 0);
291         
292         /* make sure ipowin shows it */
293         ob->ipowin= ID_CO;
294         allqueue(REDRAWIPO, ID_CO);
295         allspace(REMAKEIPO, 0);
296         allqueue(REDRAWNLA, 0);
297         
298         BIF_undo_push("Insert Influence Key");
299 }
300
301 void del_constr_func (void *ob_v, void *con_v)
302 {
303         bConstraint *con= con_v;
304         bConstraintChannel *chan;
305         ListBase *lb;
306         
307         /* remove ipo channel */
308         lb= get_active_constraint_channels(ob_v, 0);
309         if(lb) {
310                 chan = get_constraint_channel(lb, con->name);
311                 if(chan) {
312                         if(chan->ipo) chan->ipo->id.us--;
313                         BLI_freelinkN(lb, chan);
314                 }
315         }
316         /* remove constraint itself */
317         lb= get_active_constraints(ob_v);
318         free_constraint_data(con);
319         BLI_freelinkN(lb, con);
320         
321         constraint_active_func(ob_v, NULL);
322 }
323
324 static void del_constraint_func (void *ob_v, void *con_v)
325 {
326         del_constr_func (ob_v, con_v);
327         BIF_undo_push("Delete constraint");
328         allqueue(REDRAWBUTSOBJECT, 0);
329         allqueue(REDRAWIPO, 0); 
330 }
331
332 static void verify_constraint_name_func (void *con_v, void *name_v)
333 {
334         Object *ob= OBACT;
335         bConstraint *con= con_v;
336         char oldname[32];       
337         
338         if (!con)
339                 return;
340         
341         /* put on the stack */
342         BLI_strncpy(oldname, (char *)name_v, 32);
343         
344         rename_constraint(ob, con, oldname);
345         
346         constraint_active_func(ob, con);
347         allqueue(REDRAWACTION, 0); 
348 }
349
350 void const_moveUp(void *ob_v, void *con_v)
351 {
352         bConstraint *con, *constr= con_v;
353         ListBase *conlist;
354         
355         if(constr->prev) {
356                 conlist = get_active_constraints(ob_v);
357                 for(con= conlist->first; con; con= con->next) {
358                         if(con==constr) {
359                                 BLI_remlink(conlist, con);
360                                 BLI_insertlink(conlist, con->prev->prev, con);
361                                 break;
362                         }
363                 }
364         }
365 }
366
367 static void constraint_moveUp(void *ob_v, void *con_v)
368 {
369         const_moveUp(ob_v, con_v);
370         BIF_undo_push("Move constraint");
371 }
372
373 void const_moveDown(void *ob_v, void *con_v)
374 {
375         bConstraint *con, *constr= con_v;
376         ListBase *conlist;
377         
378         if(constr->next) {
379                 conlist = get_active_constraints(ob_v);
380                 for(con= conlist->first; con; con= con->next) {
381                         if(con==constr) {
382                                 BLI_remlink(conlist, con);
383                                 BLI_insertlink(conlist, con->next, con);
384                                 break;
385                         }
386                 }
387         }
388 }
389
390 static void constraint_moveDown(void *ob_v, void *con_v)
391 {
392         const_moveDown(ob_v, con_v);
393         BIF_undo_push("Move constraint");
394 }
395
396 /* autocomplete callback for  buttons */
397 void autocomplete_bone(char *str, void *arg_v)
398 {
399         Object *ob= (Object *)arg_v;
400         
401         if(ob==NULL || ob->pose==NULL) return;
402         
403         /* search if str matches the beginning of name */
404         if(str[0]) {
405                 AutoComplete *autocpl= autocomplete_begin(str, 32);
406                 bPoseChannel *pchan;
407                 
408                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
409                         autocomplete_do_name(autocpl, pchan->name);
410
411                 autocomplete_end(autocpl, str);
412         }
413 }
414
415 /* autocomplete callback for buttons */
416 void autocomplete_vgroup(char *str, void *arg_v)
417 {
418         Object *ob= (Object *)arg_v;
419         
420         if(ob==NULL) return;
421         
422         /* search if str matches the beginning of a name */
423         if(str[0]) {
424                 AutoComplete *autocpl= autocomplete_begin(str, 32);
425                 bDeformGroup *dg;
426                 
427                 for(dg= ob->defbase.first; dg; dg= dg->next)
428                         if(dg->name!=str)
429                                 autocomplete_do_name(autocpl, dg->name);
430
431                 autocomplete_end(autocpl, str);
432         }
433 }
434
435 /* pole angle callback */
436 void con_kinematic_set_pole_angle(void *ob_v, void *con_v)
437 {
438         bConstraint *con= con_v;
439         bKinematicConstraint *data = con->data;
440
441         if(data->poletar) {
442                 if(data->flag & CONSTRAINT_IK_SETANGLE) {
443                         data->flag |= CONSTRAINT_IK_GETANGLE;
444                         data->flag &= ~CONSTRAINT_IK_SETANGLE;
445                 }
446                 else {
447                         data->flag &= ~CONSTRAINT_IK_GETANGLE;
448                         data->flag |= CONSTRAINT_IK_SETANGLE;
449                 }
450         }
451 }
452
453 /* some commonly used macros in the constraints drawing code */
454 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
455 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
456 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
457
458 /* Helper function for draw constraint - draws constraint space stuff 
459  * This function should not be called if no menus are required 
460  * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode 
461  */
462 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
463 {
464         short tarx, ownx;
465         short bwidth;
466         
467         /* calculate sizes and placement of menus */
468         if (owner == -1) {
469                 bwidth = 125;
470                 tarx = 120;
471                 ownx = 0;
472         }
473         else if (target == -1) {
474                 bwidth = 125;
475                 tarx = 0;
476                 ownx = 120;
477         }
478         else {
479                 bwidth = 100;
480                 tarx = 95;
481                 ownx = tarx + bwidth;
482         }
483         
484         
485         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "CSpace:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
486         
487         uiBlockBeginAlign(block);
488         
489         /* Target-Space */
490         if (target == 1) {
491                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
492                                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
493         }
494         else if (target == 0) {
495                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
496                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
497         }
498         
499         /* Owner-Space */
500         if (owner == 1) {
501                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
502                                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
503         }
504         else if (owner == 0) {
505                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1", 
506                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
507         }
508         
509         uiBlockEndAlign(block);
510 }
511
512 /* draw panel showing settings for a constraint */
513 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
514 {
515         Object *ob= OBACT;
516         bPoseChannel *pchan= get_active_posechannel(ob);
517         bConstraintTypeInfo *cti;
518         uiBut *but;
519         char typestr[32];
520         short height, width = 265;
521         short proxy_protected;
522         int rb_col;
523
524         /* get constraint typeinfo */
525         cti= constraint_get_typeinfo(con);
526         if (cti == NULL) {
527                 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
528                 if (con->type == CONSTRAINT_TYPE_NULL)
529                         strcpy(typestr, "Null");
530                 else
531                         strcpy(typestr, "Unknown");
532         }
533         else
534                 strcpy(typestr, cti->name);
535                 
536         /* determine whether constraint is proxy protected or not */
537         if (proxylocked_constraints_owner(ob, pchan)) {
538                 proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
539         }
540         else
541                 proxy_protected= 0;
542                 
543         /* unless button has own callback, it adds this callback to button */
544         uiBlockSetFunc(block, constraint_active_func, ob, con);
545
546         /* Draw constraint header */
547         uiBlockSetEmboss(block, UI_EMBOSSN);
548         
549         /* rounded header */
550         rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20;
551         uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-1, width+40, 22, NULL, 5.0, 0.0, 
552                          (con->flag & CONSTRAINT_EXPAND)?3:15 , rb_col-20, ""); 
553         
554         /* open/close */
555         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");
556         
557         /* name */      
558         if ((con->flag & CONSTRAINT_EXPAND) && (proxy_protected==0)) {
559                 if (con->flag & CONSTRAINT_DISABLE)
560                         uiBlockSetCol(block, TH_REDALERT);
561                 
562                 uiBlockSetEmboss(block, UI_EMBOSS);
563                 
564                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
565                 
566                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
567                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
568         }       
569         else {
570                 uiBlockSetEmboss(block, UI_EMBOSSN);
571                 
572                 if (con->flag & CONSTRAINT_DISABLE)
573                         uiBlockSetCol(block, TH_REDALERT);
574                 
575                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
576                 
577                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
578         }
579
580         uiBlockSetCol(block, TH_AUTO);  
581         
582         /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
583         if (proxy_protected) {
584                 uiBlockSetEmboss(block, UI_EMBOSSN);
585                 
586                 /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
587                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, *xco+244, *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
588                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, *xco+262, *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
589                 
590                 uiBlockSetEmboss(block, UI_EMBOSS);
591         }
592         else {
593                 short prev_proxylock, show_upbut, show_downbut;
594                 
595                 /* Up/Down buttons: 
596                  *      Proxy-constraints are not allowed to occur after local (non-proxy) constraints
597                  *      as that poses problems when restoring them, so disable the "up" button where
598                  *      it may cause this situation. 
599                  *
600                  *      Up/Down buttons should only be shown (or not greyed - todo) if they serve some purpose. 
601                  */
602                 if (proxylocked_constraints_owner(ob, pchan)) {
603                         if (con->prev) {
604                                 prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
605                         }
606                         else
607                                 prev_proxylock= 0;
608                 }
609                 else
610                         prev_proxylock= 0;
611                         
612                 show_upbut= ((prev_proxylock == 0) && (con->prev));
613                 show_downbut= (con->next) ? 1 : 0;
614                 
615                 if (show_upbut || show_downbut) {
616                         uiBlockBeginAlign(block);
617                                 uiBlockSetEmboss(block, UI_EMBOSS);
618                                 
619                                 if (show_upbut) {
620                                         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 constraint up in constraint stack");
621                                         uiButSetFunc(but, constraint_moveUp, ob, con);
622                                 }
623                                 
624                                 if (show_downbut) {
625                                         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, *xco+width-50+18, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
626                                         uiButSetFunc(but, constraint_moveDown, ob, con);
627                                 }
628                         uiBlockEndAlign(block);
629                 }
630                 
631                 
632                 /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
633                 uiBlockSetEmboss(block, UI_EMBOSSN);
634                 
635                         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");
636                         uiButSetFunc(but, del_constraint_func, ob, con);
637                 
638                 uiBlockSetEmboss(block, UI_EMBOSS);
639         }
640         
641         /* Set but-locks for protected settings (magic numbers are used here!) */
642         if (proxy_protected)
643                 uiSetButLock(1, "Cannot edit Proxy-Protected Constraint");
644         
645         /* Draw constraint data */
646         if ((con->flag & CONSTRAINT_EXPAND) == 0) {
647                 (*yco) -= 21;
648         }
649         else {
650                 switch (con->type) {
651 #ifndef DISABLE_PYTHON
652                 case CONSTRAINT_TYPE_PYTHON:
653                         {
654                                 bPythonConstraint *data = con->data;
655                                 bConstraintTarget *ct;
656                                 uiBut *but2;
657                                 int tarnum, theight;
658                                 static int pyconindex=0;
659                                 char *menustr;
660                                 
661                                 theight = (data->tarnum)? (data->tarnum * 38) : (38);
662                                 height = theight + 78;
663                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40, height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
664                                 
665                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", *xco+60, *yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
666                                 
667                                 /* do the scripts menu */
668                                 menustr = buildmenu_pyconstraints(data->text, &pyconindex);
669                                 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
670                                       *xco+120, *yco-24, 150, 20, &pyconindex,
671                                       0, 0, 0, 0, "Set the Script Constraint to use");
672                                 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
673                                 MEM_freeN(menustr);     
674                                 
675                                 /* draw target(s) */
676                                 if (data->flag & PYCON_USETARGETS) {
677                                         /* Draw target parameters */ 
678                                         for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
679                                                 char tarstr[32];
680                                                 short yoffset= ((tarnum-1) * 38);
681                                                 
682                                                 /* target label */
683                                                 sprintf(tarstr, "Target %d:", tarnum);
684                                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, *xco+45, *yco-(48+yoffset), 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
685                                                 
686                                                 /* target space-selector - per target */
687                                                 if (is_armature_target(ct->tar)) {
688                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
689                                                                                                                         *xco+10, *yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");       
690                                                 }
691                                                 else {
692                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
693                                                                                                                         *xco+10, *yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");       
694                                                 }
695                                                 
696                                                 uiBlockBeginAlign(block);
697                                                         /* target object */
698                                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-(48+yoffset), 150, 18, &ct->tar, "Target Object"); 
699                                                         
700                                                         /* subtarget */
701                                                         if (is_armature_target(ct->tar)) {
702                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
703                                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
704                                                         }
705                                                         else if (is_geom_target(ct->tar)) {
706                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
707                                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
708                                                         }
709                                                         else {
710                                                                 strcpy(ct->subtarget, "");
711                                                         }
712                                                 uiBlockEndAlign(block);
713                                         }
714                                 }
715                                 else {
716                                         /* Draw indication that no target needed */
717                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+60, *yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
718                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", *xco+120, *yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
719                                 }
720                                 
721                                 /* settings */
722                                 uiBlockBeginAlign(block);
723                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Options", *xco, *yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Change some of the constraint's settings.");
724                                         uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
725                                         
726                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Refresh", *xco+((width/2)+10), *yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Force constraint to refresh it's settings");
727                                 uiBlockEndAlign(block);
728                                 
729                                 /* constraint space settings */
730                                 draw_constraint_spaceselect(block, con, *xco, *yco-(73+theight), is_armature_owner(ob), -1);
731                         }
732                         break;
733 #endif /* DISABLE_PYTHON */
734                 case CONSTRAINT_TYPE_ACTION:
735                         {
736                                 bActionConstraint *data = con->data;
737                                 float minval, maxval;
738                                 
739                                 height = 108;
740                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
741                                 
742                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
743                                 
744                                 /* Draw target parameters */
745                                 uiBlockBeginAlign(block);
746                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
747                                         
748                                         if (is_armature_target(data->tar)) {
749                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
750                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
751                                         }
752                                         else {
753                                                 strcpy(data->subtarget, "");
754                                         }
755                                 
756                                 uiBlockEndAlign(block);
757                                 
758                                 /* Draw action/type buttons */
759                                 uiBlockBeginAlign(block);
760                                         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"); 
761                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Key on%t|Loc X%x20|Loc Y%x21|Loc Z%x22|Rot X%x0|Rot Y%x1|Rot Z%x2|Size X%x10|Size Y%x11|Size Z%x12", *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");
762                                 uiBlockEndAlign(block);
763                                 
764                                 /* Draw start/end frame buttons */
765                                 uiBlockBeginAlign(block);
766                                         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"); 
767                                         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"); 
768                                 uiBlockEndAlign(block);
769                                 
770                                 /* Draw minimum/maximum transform range buttons */
771                                 uiBlockBeginAlign(block);
772                                         if (data->type < 10) { /* rotation */
773                                                 minval = -180.0f;
774                                                 maxval = 180.0f;
775                                         }
776                                         else if (data->type < 20) { /* scaling */
777                                                 minval = 0.0001f;
778                                                 maxval = 1000.0f;
779                                         }
780                                         else { /* location */
781                                                 minval = -1000.0f;
782                                                 maxval = 1000.0f;
783                                         }
784                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Min:", *xco+((width/2)+45), *yco-64, 78, 18, &data->min, minval, maxval, 0, 0, "Minimum value for target channel range");
785                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Max:", *xco+((width/2)+45), *yco-84, 78, 18, &data->max, minval, maxval, 0, 0, "Maximum value for target channel range");
786                                 uiBlockEndAlign(block);
787                                 
788                                 /* constraint space settings */
789                                 draw_constraint_spaceselect(block, con, *xco, *yco-104, -1, is_armature_target(data->tar));
790                         }
791                         break;
792                 case CONSTRAINT_TYPE_CHILDOF:
793                         {
794                                 bChildOfConstraint *data = con->data;
795                                 short normButWidth = (width/3);
796                                 
797                                 height = 165;
798                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
799                                 
800                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Parent:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
801                                 
802                                 /* Draw target parameters */
803                                 uiBlockBeginAlign(block);
804                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object to use as Parent"); 
805                                         
806                                         if (is_armature_target(data->tar)) {
807                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone to use as Parent");
808                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
809                                         }
810                                         else if (is_geom_target(data->tar)) {
811                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
812                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
813                                         }
814                                         else {
815                                                 strcpy(data->subtarget, "");
816                                         }
817                                 uiBlockEndAlign(block);
818                                 
819                                 /* Draw triples of channel toggles */
820                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Use Channel(s):", *xco+65, *yco-64, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
821                                 uiBlockBeginAlign(block); 
822                                         uiDefButBitI(block, TOG, CHILDOF_LOCX, B_CONSTRAINT_TEST, "Loc X", *xco, *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-location"); 
823                                         uiDefButBitI(block, TOG, CHILDOF_LOCY, B_CONSTRAINT_TEST, "Loc Y", *xco+normButWidth, *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-location"); 
824                                         uiDefButBitI(block, TOG, CHILDOF_LOCZ, B_CONSTRAINT_TEST, "Loc Z", *xco+(normButWidth * 2), *yco-84, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-location"); 
825                                 uiBlockEndAlign(block); 
826                                 
827                                 uiBlockBeginAlign(block); 
828                                         uiDefButBitI(block, TOG, CHILDOF_ROTX, B_CONSTRAINT_TEST, "Rot X", *xco, *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-rotation"); 
829                                         uiDefButBitI(block, TOG, CHILDOF_ROTY, B_CONSTRAINT_TEST, "Rot Y", *xco+normButWidth, *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-rotation"); 
830                                         uiDefButBitI(block, TOG, CHILDOF_ROTZ, B_CONSTRAINT_TEST, "Rot Z", *xco+(normButWidth * 2), *yco-105, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-rotation"); 
831                                 uiBlockEndAlign(block); 
832                                 
833                                 uiBlockBeginAlign(block); 
834                                         uiDefButBitI(block, TOG, CHILDOF_SIZEX, B_CONSTRAINT_TEST, "Scale X", *xco, *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects x-scaling"); 
835                                         uiDefButBitI(block, TOG, CHILDOF_SIZEY, B_CONSTRAINT_TEST, "Scale Y", *xco+normButWidth, *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects y-scaling"); 
836                                         uiDefButBitI(block, TOG, CHILDOF_SIZEZ, B_CONSTRAINT_TEST, "Scale Z", *xco+(normButWidth * 2), *yco-126, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Parent affects z-scaling"); 
837                                 uiBlockEndAlign(block);
838                                 
839                                 
840                                 /* Inverse options */
841                                 uiBlockBeginAlign(block);
842                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", *xco, *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
843                                         uiButSetFunc(but, childof_const_setinv, con, NULL);
844                                         
845                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", *xco+((width/2)+10), *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
846                                         uiButSetFunc(but, childof_const_clearinv, con, NULL);
847                                 uiBlockEndAlign(block);
848                         }
849                         break;
850                 case CONSTRAINT_TYPE_LOCLIKE:
851                         {
852                                 bLocateLikeConstraint *data = con->data;
853                                 
854                                 height = 111;
855                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
856                                 
857                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
858                                 
859                                 /* Draw target parameters */
860                                 uiBlockBeginAlign(block);
861                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
862                                         
863                                         if (is_armature_target(data->tar)) {
864                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
865                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
866                                         }
867                                         else if (is_geom_target(data->tar)) {
868                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
869                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
870                                         }
871                                         else {
872                                                 strcpy(data->subtarget, "");
873                                         }
874                                 uiBlockEndAlign(block);
875                                 
876                                 /* Draw XYZ toggles */
877                                 uiBlockBeginAlign(block);
878                                         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");
879                                         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");
880                                         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");
881                                         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");
882                                         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");
883                                         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");
884                                 uiBlockEndAlign(block);
885                                 
886                                 /* Draw options */
887                                 uiDefButBitI(block, TOG, LOCLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original location onto copied location");
888                                 if (is_armature_target(data->tar)) {
889                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco+(width/2), *yco-89, (width/2), 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
890                                 }
891                                 
892                                 /* constraint space settings */
893                                 draw_constraint_spaceselect(block, con, *xco, *yco-109, is_armature_owner(ob), is_armature_target(data->tar));
894                         }
895                         break;
896                 case CONSTRAINT_TYPE_ROTLIKE:
897                         {
898                                 bRotateLikeConstraint *data = con->data;
899                                 
900                                 height = 101;
901                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
902                                 
903                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
904                                 
905                                 /* Draw target parameters */
906                                 uiBlockBeginAlign(block);
907                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
908                                         
909                                         if (is_armature_target(data->tar)) {
910                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
911                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
912                                         }
913                                         else if (is_geom_target(data->tar)) { 
914                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
915                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
916                                         }
917                                         else {
918                                                 strcpy(data->subtarget, "");
919                                         }
920                                 uiBlockEndAlign(block);
921                                 
922                                 /* Draw XYZ toggles */
923                                 uiBlockBeginAlign(block);
924                                         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");
925                                         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");
926                                         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");
927                                         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");
928                                         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");
929                                         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");
930                                 uiBlockEndAlign(block);
931                                 
932                                 /* draw offset toggle */
933                                 uiDefButBitI(block, TOG, ROTLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-64, 80, 18, &data->flag, 0, 24, 0, 0, "Add original rotation onto copied rotation");
934                                 
935                                 /* constraint space settings */
936                                 draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
937                         }
938                         break;
939                 case CONSTRAINT_TYPE_SIZELIKE:
940                         {
941                                 bSizeLikeConstraint *data = con->data;
942                                 
943                                 height = 101;
944                                 
945                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
946                                 
947                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
948                                 
949                                 /* Draw target parameters */
950                                 uiBlockBeginAlign(block);
951                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
952                                         
953                                         if (is_armature_target(data->tar)) {
954                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
955                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
956                                         }
957                                         else if (is_geom_target(data->tar)) {
958                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
959                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
960                                         }
961                                         else {
962                                                 strcpy(data->subtarget, "");
963                                         }
964                                 uiBlockEndAlign(block);
965                                 
966                                 /* Draw XYZ toggles */
967                                 uiBlockBeginAlign(block);
968                                         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");
969                                         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");
970                                         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");
971                                 uiBlockEndAlign(block);
972                                 
973                                 /* draw offset toggle */
974                                 uiDefButBitI(block, TOG, SIZELIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco, *yco-64, 80, 18, &data->flag, 0, 24, 0, 0, "Add original scaling onto copied scaling");
975                                 
976                                 /* constraint space settings */
977                                 draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
978                         }
979                         break;
980                 case CONSTRAINT_TYPE_KINEMATIC:
981                         {
982                                 bKinematicConstraint *data = con->data;
983                                 
984                                 height = 146;
985                                 if(data->poletar) 
986                                         height += 30;
987
988                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
989                                 
990                                 /* IK Target */
991                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco, *yco-24, 80, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
992                                 
993                                 /* Draw target parameters */
994                                 uiBlockBeginAlign(block);
995                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco, *yco-44, 137, 19, &data->tar, "Target Object"); 
996
997                                 if (is_armature_target(data->tar)) {
998                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco, *yco-62,137,19, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
999                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1000                                 }
1001                                 else if (is_geom_target(data->tar)) {
1002                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco, *yco-62,137,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1003                                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1004                                 }
1005                                 else {
1006                                         strcpy (data->subtarget, "");
1007                                 }
1008                                 
1009                                 uiBlockEndAlign(block);
1010                                 
1011                                 /* Settings */
1012                                 uiBlockBeginAlign(block);
1013                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_TIP, B_CONSTRAINT_TEST, "Use Tail", *xco, *yco-92, 137, 19, &data->flag, 0, 0, 0, 0, "Include Bone's tail also last element in Chain");
1014                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "ChainLen:", *xco, *yco-112,137,19, &data->rootbone, 0, 255, 0, 0, "If not zero, the amount of bones in this chain");
1015                                 
1016                                 uiBlockBeginAlign(block);
1017                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "PosW ", *xco+147, *yco-92, 137, 19, &data->weight, 0.01, 1.0, 2, 2, "For Tree-IK: weight of position control for this target");
1018                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_ROT, B_CONSTRAINT_TEST, "Rot", *xco+147, *yco-112, 40,19, &data->flag, 0, 0, 0, 0, "Chain follows rotation of target");
1019                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "W ", *xco+187, *yco-112, 97, 19, &data->orientweight, 0.01, 1.0, 2, 2, "For Tree-IK: Weight of orientation control for this target");
1020                                 
1021                                 uiBlockBeginAlign(block);
1022                                 
1023                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_STRETCH, B_CONSTRAINT_TEST, "Stretch", *xco, *yco-137,137,19, &data->flag, 0, 0, 0, 0, "Enable IK stretching");
1024                                 uiBlockBeginAlign(block);
1025                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "Iterations:", *xco+147, *yco-137, 137, 19, &data->iterations, 1, 10000, 0, 0, "Maximum number of solving iterations"); 
1026                                 uiBlockEndAlign(block);
1027                                 
1028                                 /* Pole Vector */
1029                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Pole Target:", *xco+147, *yco-24, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1030                                 
1031                                 uiBlockBeginAlign(block);
1032                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+147, *yco-44, 137, 19, &data->poletar, "Pole Target Object"); 
1033                                 if (is_armature_target(data->poletar)) {
1034                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+147, *yco-62,137,19, &data->polesubtarget, 0, 24, 0, 0, "Pole Subtarget Bone");
1035                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->poletar);
1036                                 }
1037                                 else if (is_geom_target(data->poletar)) {
1038                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+147, *yco-62,137,18, &data->polesubtarget, 0, 24, 0, 0, "Name of Vertex Group defining pole 'target' points");
1039                                         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->poletar);
1040                                 }
1041                                 else {
1042                                         strcpy(data->polesubtarget, "");
1043                                 }
1044                                 
1045                                 if (data->poletar) {
1046                                         uiBlockBeginAlign(block);
1047 #if 0
1048                                         but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, (data->flag & CONSTRAINT_IK_SETANGLE)? "Set Pole Offset": "Clear Pole Offset", *xco, *yco-167, 137, 19, 0, 0.0, 1.0, 0.0, 0.0, "Set the pole rotation offset from the current pose");
1049                                         uiButSetFunc(but, con_kinematic_set_pole_angle, ob, con);
1050                                         if (!(data->flag & CONSTRAINT_IK_SETANGLE))
1051 #endif                                  
1052                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pole Offset ", *xco, *yco-167, 137, 19, &data->poleangle, -180.0, 180.0, 0, 0, "Pole rotation offset");
1053                                 }
1054                         }
1055                         break;
1056                 case CONSTRAINT_TYPE_TRACKTO:
1057                         {
1058                                 bTrackToConstraint *data = con->data;
1059                                 
1060                                 if (is_armature_target(data->tar)) 
1061                                         height = 118;
1062                                 else
1063                                         height = 96;
1064                                         
1065                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1066                                 
1067                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1068                                 
1069                                 /* Draw target parameters */
1070                                 uiBlockBeginAlign(block);
1071                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1072                                         
1073                                         if (is_armature_target(data->tar)) {
1074                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1075                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1076                                         }
1077                                         else if (is_geom_target(data->tar)) {
1078                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1079                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1080                                         }
1081                                         else {
1082                                                 strcpy(data->subtarget, "");
1083                                         }
1084                                 uiBlockEndAlign(block);
1085                                 
1086                                 uiBlockBeginAlign(block);
1087                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Align:", *xco+5, *yco-42, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1088                                         
1089                                         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");
1090                                 uiBlockEndAlign(block);
1091                                 
1092                                 uiBlockBeginAlign(block);
1093                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1094                                         
1095                                         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");
1096                                         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");
1097                                         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");
1098                                         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");
1099                                         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");
1100                                         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");
1101                                 uiBlockEndAlign(block);
1102                                 
1103                                 uiBlockBeginAlign(block);
1104                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1105                                         
1106                                         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");
1107                                         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");
1108                                         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");
1109                                 uiBlockEndAlign(block);
1110                                 
1111                                 if (is_armature_target(data->tar)) {
1112                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco, *yco-94, 241, 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1113                                         
1114                                         /* constraint space settings */
1115                                         draw_constraint_spaceselect(block, con, *xco, *yco-116, is_armature_owner(ob), is_armature_target(data->tar));
1116                                 }
1117                                 else {
1118                                         /* constraint space settings */
1119                                         draw_constraint_spaceselect(block, con, *xco, *yco-94, is_armature_owner(ob), is_armature_target(data->tar));
1120                                 }
1121                         }
1122                         break;
1123                 case CONSTRAINT_TYPE_MINMAX:
1124                         {
1125                                 bMinMaxConstraint *data = con->data;
1126                                 
1127                                 if (is_armature_target(data->tar)) 
1128                                         height = 88;
1129                                 else
1130                                         height = 66;
1131                                         
1132                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1133                                 
1134                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1135                                 
1136                                 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"); 
1137                                 
1138                                 /* Draw target parameters */
1139                                 uiBlockBeginAlign(block);
1140                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1141                                         
1142                                         if (is_armature_target(data->tar)) {
1143                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1144                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1145                                         }
1146                                         else if (is_geom_target(data->tar)) {
1147                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1148                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1149                                         }
1150                                         else {
1151                                                 strcpy(data->subtarget, "");
1152                                         }
1153                                 uiBlockEndAlign(block);
1154                                 
1155                                 uiDefButBitI(block, TOG, MINMAX_STICKY, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 44, 18, &data->flag, 0, 24, 0, 0, "Immobilize object while constrained");
1156                                 uiDefButBitI(block, TOG, MINMAX_USEROT, B_CONSTRAINT_TEST, "Use Rot", *xco+44, *yco-24, 64, 18, &data->flag, 0, 24, 0, 0, "Use target object rotation");
1157                                 
1158                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1159                                 
1160                                 uiBlockBeginAlign(block);                       
1161                                         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");
1162                                         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");
1163                                         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");
1164                                         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");
1165                                         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");
1166                                         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");
1167                                 uiBlockEndAlign(block);
1168                                 
1169                                 if (is_armature_target(data->tar)) {
1170                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco, *yco-86, 241, 18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1171                                 }
1172                                 
1173                         }
1174                         break;
1175                 case CONSTRAINT_TYPE_LOCKTRACK:
1176                         {
1177                                 bLockTrackConstraint *data = con->data;
1178                                 height = 66;
1179                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1180                                 
1181                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1182                                 
1183                                 /* Draw target parameters */
1184                                 uiBlockBeginAlign(block);
1185                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1186                                         
1187                                         if (is_armature_target(data->tar)) {
1188                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1189                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1190                                         }
1191                                         else if (is_geom_target(data->tar)) {
1192                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1193                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1194                                         }
1195                                         else {
1196                                                 strcpy(data->subtarget, "");
1197                                         }
1198                                 uiBlockEndAlign(block);
1199                                 
1200                                 uiBlockBeginAlign(block);
1201                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1202                                         
1203                                         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");
1204                                         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");
1205                                         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");
1206                                         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");
1207                                         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");
1208                                         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");
1209                                 uiBlockEndAlign(block);
1210                                 
1211                                 uiBlockBeginAlign(block);
1212                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1213                                         
1214                                         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");
1215                                         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");
1216                                         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");
1217                                 uiBlockEndAlign(block);
1218                         }
1219                         break;
1220                 case CONSTRAINT_TYPE_FOLLOWPATH:
1221                         {
1222                                 bFollowPathConstraint *data = con->data;
1223                                 
1224                                 height = 66;
1225                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1226                                 
1227                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1228                                 
1229                                 /* Draw target parameters */
1230                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1231                                 
1232                                 /* Draw Curve Follow toggle */
1233                                 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");
1234                                 
1235                                 /* Draw Offset number button */
1236                                 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"); 
1237                                 
1238                                 uiBlockBeginAlign(block);
1239                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1240                                         
1241                                         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");
1242                                         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");
1243                                         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");
1244                                         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");
1245                                         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");
1246                                         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");
1247                                 uiBlockEndAlign(block);
1248                                 
1249                                 uiBlockBeginAlign(block);
1250                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1251                                         
1252                                         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");
1253                                         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");
1254                                         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");
1255                                 uiBlockEndAlign(block);
1256                         }
1257                         break;
1258                 case CONSTRAINT_TYPE_STRETCHTO:
1259                         {
1260                                 bStretchToConstraint *data = con->data;
1261                                 
1262                                 height = 105;
1263                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1264                                 
1265                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1266                                 
1267                                 /* Draw target parameters */
1268                                 uiBlockBeginAlign(block);
1269                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1270                                         
1271                                         if (is_armature_target(data->tar)) {
1272                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1273                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1274                                         }
1275                                         else if (is_geom_target(data->tar)) {
1276                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1277                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1278                                         }
1279                                         else {
1280                                                 strcpy(data->subtarget, "");
1281                                         }
1282                                 uiBlockEndAlign(block);
1283                                 
1284                                 uiBlockBeginAlign(block);
1285                                         if (is_armature_target(data->tar)) {
1286                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->orglength, 0.0, 0, 0, 0, "Recalculate RLength");
1287                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Rest Length:", *xco+18, *yco-60,139,18, &data->orglength, 0.0, 100, 0.5, 0.5, "Length at Rest Position");
1288                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco+155, *yco-60,98,18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1289                                         }
1290                                         else {
1291                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->orglength, 0.0, 0, 0, 0, "Recalculate RLength");
1292                                                 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");
1293                                         }
1294                                 uiBlockEndAlign(block);
1295                                 
1296                                 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");
1297                                 
1298                                 uiBlockBeginAlign(block);
1299                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Vol:",*xco+14, *yco-104,30,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1300                                         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");
1301                                         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");
1302                                         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");
1303                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"NONE", *xco+114, *yco-104,50,18, &data->volmode, 12.0, 3.0, 0, 0, "Ignore Volume");
1304                                 uiBlockEndAlign(block);
1305                                 
1306                                 uiBlockBeginAlign(block);
1307                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Plane:",*xco+175, *yco-104,40,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1308                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",       *xco+215, *yco-104,20,18, &data->plane, 12.0, 0.0, 0, 0, "Keep X axis");
1309                                         uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",       *xco+235, *yco-104,20,18, &data->plane, 12.0, 2.0, 0, 0, "Keep Z axis");
1310                                 uiBlockEndAlign(block);
1311                                 }
1312                         break;
1313                 case CONSTRAINT_TYPE_LOCLIMIT:
1314                         {
1315                                 bLocLimitConstraint *data = con->data;
1316                                 
1317                                 int togButWidth = 50;
1318                                 int textButWidth = ((width/2)-togButWidth);
1319                                 
1320                                 height = 136; 
1321                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1322                                 
1323                                 /* Draw Pairs of LimitToggle+LimitValue */
1324                                 uiBlockBeginAlign(block); 
1325                                         uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1326                                         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"); 
1327                                 uiBlockEndAlign(block); 
1328                                 
1329                                 uiBlockBeginAlign(block); 
1330                                         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"); 
1331                                         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"); 
1332                                 uiBlockEndAlign(block); 
1333                                 
1334                                 uiBlockBeginAlign(block); 
1335                                         uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1336                                         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"); 
1337                                 uiBlockEndAlign(block);
1338                                 
1339                                 uiBlockBeginAlign(block); 
1340                                         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"); 
1341                                         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"); 
1342                                 uiBlockEndAlign(block); 
1343                                 
1344                                 uiBlockBeginAlign(block); 
1345                                         uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1346                                         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"); 
1347                                 uiBlockEndAlign(block);
1348                                 
1349                                 uiBlockBeginAlign(block); 
1350                                         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"); 
1351                                         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"); 
1352                                 uiBlockEndAlign(block);
1353                                 
1354                                 /* special option(s) */
1355                                 uiDefButBitS(block, TOG, LIMIT_TRANSFORM, B_CONSTRAINT_TEST, "For Transform", *xco+(width/4), *yco-100, (width/2), 18, &data->flag2, 0, 24, 0, 0, "Transforms are affected by this constraint as well"); 
1356                                 
1357                                 /* constraint space settings */
1358                                 draw_constraint_spaceselect(block, con, *xco, *yco-130, is_armature_owner(ob), -1);
1359                         }
1360                         break;
1361                 case CONSTRAINT_TYPE_ROTLIMIT:
1362                         {
1363                                 bRotLimitConstraint *data = con->data;
1364                                 int normButWidth = (width/3);
1365                                 
1366                                 height = 136; 
1367                                 
1368                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1369                                 
1370                                 /* Draw Pairs of LimitToggle+LimitValue */
1371                                 uiBlockBeginAlign(block); 
1372                                         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"); 
1373                                         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"); 
1374                                         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"); 
1375                                 uiBlockEndAlign(block); 
1376                                 
1377                                 uiBlockBeginAlign(block); 
1378                                         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"); 
1379                                         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"); 
1380                                         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"); 
1381                                 uiBlockEndAlign(block); 
1382                                 
1383                                 uiBlockBeginAlign(block); 
1384                                         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"); 
1385                                         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"); 
1386                                         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"); 
1387                                 uiBlockEndAlign(block); 
1388                                 
1389                                 /* special option(s) */
1390                                 uiDefButBitS(block, TOG, LIMIT_TRANSFORM, B_CONSTRAINT_TEST, "For Transform", *xco+(width/4), *yco-100, (width/2), 18, &data->flag2, 0, 24, 0, 0, "Transforms are affected by this constraint as well"); 
1391                                 
1392                                 /* constraint space settings */
1393                                 draw_constraint_spaceselect(block, con, *xco, *yco-130, is_armature_owner(ob), -1);
1394                         }
1395                         break;
1396                 case CONSTRAINT_TYPE_SIZELIMIT:
1397                         {
1398                                 bSizeLimitConstraint *data = con->data;
1399                                 
1400                                 int togButWidth = 50;
1401                                 int textButWidth = ((width/2)-togButWidth);
1402                                 
1403                                 height = 136; 
1404                                         
1405                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1406                                 
1407                                 /* Draw Pairs of LimitToggle+LimitValue */
1408                                 uiBlockBeginAlign(block); 
1409                                         uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1410                                         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"); 
1411                                 uiBlockEndAlign(block); 
1412                                 
1413                                 uiBlockBeginAlign(block); 
1414                                         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"); 
1415                                         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"); 
1416                                 uiBlockEndAlign(block); 
1417                                 
1418                                 
1419                                 uiBlockBeginAlign(block); 
1420                                         uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1421                                         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"); 
1422                                 uiBlockEndAlign(block); 
1423                                 
1424                                 uiBlockBeginAlign(block); 
1425                                         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"); 
1426                                         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"); 
1427                                 uiBlockEndAlign(block); 
1428                                 
1429                                 
1430                                 uiBlockBeginAlign(block); 
1431                                         uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1432                                         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"); 
1433                                 uiBlockEndAlign(block); 
1434                                 
1435                                 uiBlockBeginAlign(block); 
1436                                         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"); 
1437                                         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"); 
1438                                 uiBlockEndAlign(block);
1439                                 
1440                                 /* special option(s) */
1441                                 uiDefButBitS(block, TOG, LIMIT_TRANSFORM, B_CONSTRAINT_TEST, "For Transform", *xco+(width/4), *yco-100, (width/2), 18, &data->flag2, 0, 24, 0, 0, "Transforms are affected by this constraint as well"); 
1442                                 
1443                                 /* constraint space settings */
1444                                 draw_constraint_spaceselect(block, con, *xco, *yco-130, is_armature_owner(ob), -1);
1445                         }
1446                         break;
1447                 case CONSTRAINT_TYPE_DISTLIMIT:
1448                         {
1449                                 bDistLimitConstraint *data = con->data;
1450                                 
1451                                 height = 105;
1452                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1453                                 
1454                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1455                                 
1456                                 /* Draw target parameters */
1457                                 uiBlockBeginAlign(block);
1458                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1459                                         
1460                                         if (is_armature_target(data->tar)) {
1461                                                 but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1462                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1463                                         }
1464                                         else if (is_geom_target(data->tar)) {
1465                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1466                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1467                                         }
1468                                         else {
1469                                                 strcpy(data->subtarget, "");
1470                                         }
1471                                 uiBlockEndAlign(block);
1472                                 
1473                                 uiBlockBeginAlign(block);
1474                                         if (is_armature_target(data->tar)) {
1475                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->dist, 0, 0, 0, 0, "Recalculate distance"); 
1476                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Distance:", *xco+18, *yco-60,139,18, &data->dist, 0.0, 100, 0.5, 0.5, "Radius of limiting sphere");
1477                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Head/Tail:", *xco+155, *yco-60,100,18, &con->headtail, 0.0, 1, 0.1, 0.1, "Target along length of bone: Head=0, Tail=1");
1478                                         }
1479                                         else {
1480                                                 uiDefButF(block, BUTM, B_CONSTRAINT_TEST, "R", *xco, *yco-60, 20, 18, &data->dist, 0, 0, 0, 0, "Recalculate distance"); 
1481                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Distance:", *xco+18, *yco-60, 237, 18, &data->dist, 0.0, 100, 0.5, 0.5, "Radius of limiting sphere");
1482                                         }
1483                                         
1484                                         /* disabled soft-distance controls... currently it doesn't work yet. It was intended to be used for soft-ik (see xsi-blog for details) */
1485 #if 0
1486                                         uiDefButBitS(block, TOG, LIMITDIST_USESOFT, B_CONSTRAINT_TEST, "Soft", *xco, *yco-82, 50, 18, &data->flag, 0, 24, 0, 0, "Enables soft-distance");
1487                                         if (data->flag & LIMITDIST_USESOFT)
1488                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Soft-Distance:", *xco+50, *yco-82, 187, 18, &data->soft, 0.0, 100, 0.5, 0.5, "Distance surrounding radius when transforms should get 'delayed'");
1489 #endif
1490                                 uiBlockEndAlign(block);
1491                                 
1492                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Clamp Region:",*xco+((width/2)-110), *yco-104,100,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1493                                 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Limit Mode%t|Inside %x0|Outside %x1|Surface %x2", *xco+(width/2), *yco-104, 100, 18, &data->mode, 0, 24, 0, 0, "Distances in relation to sphere of influence to allow");
1494                         }
1495                         break;
1496                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1497                         {
1498                                 bRigidBodyJointConstraint *data = con->data;
1499                                 float extremeLin = 999.f;
1500                                 float extremeAngX = 180.f;
1501                                 float extremeAngY = 45.f;
1502                                 float extremeAngZ = 45.f;
1503                                 int togButWidth = 70;
1504                                 int offsetY = 150;
1505                                 int textButWidth = ((width/2)-togButWidth);
1506                                 
1507                 height = 140;
1508                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1509                                         height = 270;
1510                                 if (data->type==CONSTRAINT_RB_CONETWIST)
1511                                         height = 200;
1512                                 
1513                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1514
1515                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Generic 6DOF%x12",//|Extra Force%x6",
1516                                 //uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Cone Twist%x4|Generic 6DOF%x12",//|Extra Force%x6",
1517                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1518
1519                                 uiDefButBitS(block, TOG, CONSTRAINT_DISABLE_LINKED_COLLISION, B_CONSTRAINT_TEST, "No Collision", *xco+155, *yco-25, 111, 18, &data->flag, 0, 24, 0, 0, "Disable Collision Between Linked Bodies");
1520
1521
1522                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1523                                 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");                              
1524                                 
1525                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1526                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1527                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1528                                 
1529                                 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)");
1530                                 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)");
1531                                 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)");
1532                                 
1533                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
1534                                         /* Draw Pairs of LimitToggle+LimitValue */
1535                                         uiBlockBeginAlign(block); 
1536                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1537                                                 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"); 
1538                                         uiBlockEndAlign(block);
1539                                         
1540                                         uiBlockBeginAlign(block); 
1541                                                 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"); 
1542                                                 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"); 
1543                                         uiBlockEndAlign(block);
1544                                         
1545                                         offsetY += 20;
1546                                         uiBlockBeginAlign(block); 
1547                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1548                                                 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"); 
1549                                         uiBlockEndAlign(block);
1550                                         
1551                                         uiBlockBeginAlign(block); 
1552                                                 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"); 
1553                                                 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"); 
1554                                         uiBlockEndAlign(block);
1555                                         
1556                                         offsetY += 20;
1557                                         uiBlockBeginAlign(block); 
1558                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1559                                                 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"); 
1560                                         uiBlockEndAlign(block);
1561                                         
1562                                         uiBlockBeginAlign(block); 
1563                                                 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"); 
1564                                                 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"); 
1565                                         uiBlockEndAlign(block);
1566                                         offsetY += 20;
1567                                 }
1568                                 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
1569                                         /* Draw Pairs of LimitToggle+LimitValue */
1570                                         uiBlockBeginAlign(block); 
1571                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1572                                                 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"); 
1573                                         uiBlockEndAlign(block);
1574                                         uiBlockBeginAlign(block); 
1575                                                 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"); 
1576                                                 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"); 
1577                                         uiBlockEndAlign(block);
1578                                         
1579                                         offsetY += 20;
1580                                         uiBlockBeginAlign(block); 
1581                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1582                                                 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"); 
1583                                         uiBlockEndAlign(block);
1584                                         
1585                                         uiBlockBeginAlign(block); 
1586                                                 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"); 
1587                                                 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"); 
1588                                         uiBlockEndAlign(block);
1589                                         
1590                                         offsetY += 20;
1591                                         uiBlockBeginAlign(block); 
1592                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1593                                                 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"); 
1594                                         uiBlockEndAlign(block);
1595                                         
1596                                         uiBlockBeginAlign(block); 
1597                                                 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"); 
1598                                                 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"); 
1599                                         uiBlockEndAlign(block);
1600                                 }
1601                                 
1602                         }
1603                         break;
1604                 case CONSTRAINT_TYPE_CLAMPTO:
1605                         {
1606                                 bClampToConstraint *data = con->data;
1607                                 
1608                                 height = 90;
1609                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1610                                 
1611                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1612                                 
1613                                 /* Draw target parameters */
1614                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1615                                 
1616                                 /* Draw XYZ toggles */
1617                                 uiBlockBeginAlign(block);
1618                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1619                                         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");
1620                                         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");
1621                                         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");
1622                                         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");
1623                                 uiBlockEndAlign(block);
1624                                 
1625                                 /* Extra Options Controlling Behaviour */
1626                                 //uiBlockBeginAlign(block);
1627                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Options:", *xco, *yco-88, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1628                                         uiDefButBitI(block, TOG, CLAMPTO_CYCLIC, B_CONSTRAINT_TEST, "Cyclic", *xco+((width/2)), *yco-88,60,19, &data->flag2, 0, 0, 0, 0, "Treat curve as cyclic curve (no clamping to curve bounding box)");
1629                                 //uiBlockEndAlign(block);
1630                         }
1631                         break;
1632                 case CONSTRAINT_TYPE_TRANSFORM:
1633                         {
1634                                 bTransformConstraint *data = con->data;
1635                                 float fmin, fmax, tmin, tmax;
1636                                 
1637                                 height = 178;
1638                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1639                                 
1640                                 /* Draw target parameters */                    
1641                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1642                                 
1643                                 /* Draw target parameters */
1644                                 uiBlockBeginAlign(block);
1645                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object to use as Parent"); 
1646                                         
1647                                         if (is_armature_target(data->tar)) {
1648                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone to use as Parent");
1649                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1650                                         }
1651                                         else if (is_geom_target(data->tar)) {
1652                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1653                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1654                                         }
1655                                         else {
1656                                                 strcpy(data->subtarget, "");
1657                                         }
1658                                 uiBlockEndAlign(block);
1659                                 
1660                                 /* Extrapolate Ranges? */
1661                                 uiDefButBitC(block, TOG, 1, B_CONSTRAINT_TEST, "Extrapolate", *xco-10, *yco-42,80,19, &data->expo, 0, 0, 0, 0, "Extrapolate ranges");
1662                                 
1663                                 /* Draw options for source motion */
1664                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Source:", *xco-10, *yco-62, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1665                                 
1666                                 /*      draw Loc/Rot/Size toggles       */
1667                                 uiBlockBeginAlign(block);
1668                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco-5, *yco-82, 45, 18, &data->from, 12.0, 0, 0, 0, "Use Location transform channels from Target");
1669                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+40, *yco-82, 45, 18, &data->from, 12.0, 1, 0, 0, "Use Rotation transform channels from Target");
1670                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+85, *yco-82, 45, 18, &data->from, 12.0, 2, 0, 0, "Use Scale transform channels from Target");
1671                                 uiBlockEndAlign(block);
1672                                 
1673                                 /* Draw Pairs of Axis: Min/Max Value*/
1674                                 if (data->from == 2) {
1675                                         fmin= 0.0001;
1676                                         fmax= 1000.0;
1677                                 }
1678                                 else if (data->from == 1) {
1679                                         fmin= -360.0;
1680                                         fmax= 360.0;
1681                                 }
1682                                 else {
1683                                         fmin = -1000.0;
1684                                         fmax= 1000.0;
1685                                 }
1686                                 
1687                                 uiBlockBeginAlign(block); 
1688                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "X:", *xco-10, *yco-107, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1689                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-107, 55, 18, &data->from_min[0], fmin, fmax, 0, 0, "Bottom of range of x-axis source motion for source->target mapping"); 
1690                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-107, 55, 18, &data->from_max[0], fmin, fmax, 0, 0, "Top of range of x-axis source motion for source->target mapping"); 
1691                                 uiBlockEndAlign(block); 
1692                                 
1693                                 uiBlockBeginAlign(block); 
1694                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Y:", *xco-10, *yco-127, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1695                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-127, 55, 18, &data->from_min[1], fmin, fmax, 0, 0, "Bottom of range of y-axis source motion for source->target mapping"); 
1696                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-127, 55, 18, &data->from_max[1], fmin, fmax, 0, 0, "Top of range of y-axis source motion for source->target mapping"); 
1697                                 uiBlockEndAlign(block);
1698                                 
1699                                 uiBlockBeginAlign(block); 
1700                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Z:", *xco-10, *yco-147, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1701                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+20, *yco-147, 55, 18, &data->from_min[2], fmin, fmax, 0, 0, "Bottom of range of z-axis source motion for source->target mapping"); 
1702                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+75, *yco-147, 55, 18, &data->from_max[2], fmin, fmax, 0, 0, "Top of range of z-axis source motion for source->target mapping"); 
1703                                 uiBlockEndAlign(block); 
1704                                 
1705                                 
1706                                 /* Draw options for target motion */
1707                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Destination:", *xco+150, *yco-62, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1708                                 
1709                                 /*      draw Loc/Rot/Size toggles       */
1710                                 uiBlockBeginAlign(block);
1711                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco+150, *yco-82, 45, 18, &data->to, 12.0, 0, 0, 0, "Use as Location transform");
1712                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+195, *yco-82, 45, 18, &data->to, 12.0, 1, 0, 0, "Use as Rotation transform");
1713                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+245, *yco-82, 45, 18, &data->to, 12.0, 2, 0, 0, "Use as Scale transform");
1714                                 uiBlockEndAlign(block);
1715                                 
1716                                 /* Draw Pairs of Source-Axis: Min/Max Value*/
1717                                 if (data->to == 2) {
1718                                         tmin= 0.0001;
1719                                         tmax= 1000.0;
1720                                 }
1721                                 else if (data->to == 1) {
1722                                         tmin= -360.0;
1723                                         tmax= 360.0;
1724                                 }
1725                                 else {
1726                                         tmin = -1000.0;
1727                                         tmax= 1000.0;
1728                                 }
1729                                 
1730                                 uiBlockBeginAlign(block); 
1731                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->X%x0|Y->X%x1|Z->X%x2", *xco+150, *yco-107, 40, 18, &data->map[0], 0, 24, 0, 0, "Specify which source axis the x-axis destination uses");
1732                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-107, 50, 18, &data->to_min[0], tmin, tmax, 0, 0, "Bottom of range of x-axis destination motion for source->target mapping"); 
1733                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-107, 50, 18, &data->to_max[0], tmin, tmax, 0, 0, "Top of range of x-axis destination motion for source->target mapping"); 
1734                                 uiBlockEndAlign(block); 
1735                                 
1736                                 uiBlockBeginAlign(block); 
1737                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->Y%x0|Y->Y%x1|Z->Y%x2", *xco+150, *yco-127, 40, 18, &data->map[1], 0, 24, 0, 0, "Specify which source axis the y-axis destination uses");
1738                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-127, 50, 18, &data->to_min[1], tmin, tmax, 0, 0, "Bottom of range of y-axis destination motion for source->target mapping"); 
1739                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-127, 50, 18, &data->to_max[1], tmin, tmax, 0, 0, "Top of range of y-axis destination motion for source->target mapping"); 
1740                                 uiBlockEndAlign(block);
1741                                 
1742                                 uiBlockBeginAlign(block); 
1743                                         uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Axis Mapping%t|X->Z%x0|Y->Z%x1|Z->Z%x2", *xco+150, *yco-147, 40, 18, &data->map[2], 0, 24, 0, 0, "Specify which source axis the z-axis destination uses");
1744                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min", *xco+175, *yco-147, 50, 18, &data->to_min[2], tmin, tmax, 0, 0, "Bottom of range of z-axis destination motion for source->target mapping"); 
1745                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max", *xco+240, *yco-147, 50, 18, &data->to_max[2], tmin, tmax, 0, 0, "Top of range of z-axis destination motion for source->target mapping"); 
1746                                 uiBlockEndAlign(block); 
1747                                 
1748                                 /* constraint space settings */
1749                                 draw_constraint_spaceselect(block, con, *xco, *yco-170, is_armature_owner(ob), is_armature_target(data->tar));
1750                         }
1751                         break;
1752                 case CONSTRAINT_TYPE_NULL:
1753                         {
1754                                 height = 17;
1755                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1756                         }
1757                         break;
1758
1759                 case CONSTRAINT_TYPE_SHRINKWRAP:
1760                         {
1761                                 bShrinkwrapConstraint *data = con->data;
1762
1763                                 height = 78;
1764                                 if(data->shrinkType == MOD_SHRINKWRAP_PROJECT)
1765                                         height += 18;
1766
1767                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1768
1769                                 /* Draw parameters */
1770                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1771                                 uiDefIDPoinBut(block, test_meshobpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->target, "Target Object");
1772
1773                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Dist:", *xco + 75, *yco-42, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1774                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+120, *yco-42, 135, 18, &data->dist, -100.0f, 100.0f, 1.0f, 0.0f, "Distance to target");
1775
1776                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Type:", *xco + 70, *yco-60, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1777                                 uiDefButS(block, MENU, B_MODIFIER_RECALC, "Shrinkwrap Type%t|Nearest Surface Point %x0|Projection %x1|Nearest Vertex %x2", *xco+120, *yco-60, 135, 18, &data->shrinkType, 0, 0, 0, 0, "Selects type of shrinkwrap algorithm for target position.");
1778
1779                                 if(data->shrinkType == MOD_SHRINKWRAP_PROJECT)
1780                                 {
1781                                         /* Draw XYZ toggles */
1782                                         uiDefBut(block, LABEL,B_CONSTRAINT_TEST, "Axis:", *xco+ 75, *yco-78, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1783                                         uiDefButBitC(block, TOG, MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS, B_CONSTRAINT_TEST, "X",*xco+120, *yco-78, 45, 18, &data->projAxis, 0, 0, 0, 0, "Projection over X axis");
1784                                         uiDefButBitC(block, TOG, MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS, B_CONSTRAINT_TEST, "Y",*xco+165, *yco-78, 45, 18, &data->projAxis, 0, 0, 0, 0, "Projection over Y axis");
1785                                         uiDefButBitC(block, TOG, MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS, B_CONSTRAINT_TEST, "Z",*xco+210, *yco-78, 45, 18, &data->projAxis, 0, 0, 0, 0, "Projection over Z axis");
1786                                 }
1787                         }
1788                         break;
1789                 default:
1790                         height = 0;
1791                         break;
1792                 }
1793                 
1794                 (*yco)-=(24+height);
1795         }
1796
1797         if (ELEM(con->type, CONSTRAINT_TYPE_NULL, CONSTRAINT_TYPE_RIGIDBODYJOINT)==0) {
1798                 uiBlockBeginAlign(block);
1799                 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");
1800                 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");
1801                 /* If this is on an object or bone, add ipo channel the constraint */
1802                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1803                 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");
1804                 /* Add a keyframe to the influence IPO */
1805                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1806                 uiBlockEndAlign(block);
1807                 (*yco)-=24;
1808         } 
1809         else {
1810                 (*yco)-=3;
1811         }
1812         
1813         /* clear any locks set up for proxies/lib-linking */
1814         uiClearButLock();
1815 }
1816
1817 static uiBlock *add_constraintmenu(void *arg_unused)
1818 {
1819         Object *ob= OBACT;
1820         uiBlock *block;
1821         ListBase *conlist;
1822         short yco= 0;
1823         
1824         conlist = get_active_constraints(ob);
1825         
1826         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1827
1828         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CHILDOF, "Child Of",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1829         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRANSFORM, "Transformation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1830         
1831         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1832         
1833         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE, "Copy Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1834         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE, "Copy Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1835         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE, "Copy Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1836         
1837         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1838         
1839         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT, "Limit Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1840         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT, "Limit Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1841         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT, "Limit Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1842         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_DISTLIMIT, "Limit Distance", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1843         
1844         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1845         
1846         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO, "Track To",     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1847         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX, "Floor", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1848         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK, "Locked Track", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1849         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH, "Follow Path", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1850         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SHRINKWRAP, "Shrinkwrap" , 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1851                 
1852         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1853         
1854         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO, "Clamp To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1855         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO, "Stretch To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1856
1857         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT, "Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1858
1859         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1860         
1861         if (ob->flag & OB_POSEMODE) {
1862                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC, "IK Solver", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1863         }
1864         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION, "Action", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1865         
1866         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1867
1868         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_PYTHON, "Script", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1869         
1870         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1871         
1872         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL, "Null",    0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1873         
1874         
1875         uiTextBoundsBlock(block, 50);
1876         uiBlockSetDirection(block, UI_DOWN);
1877                 
1878         return block;
1879 }
1880
1881 void do_constraintbuts(unsigned short event)
1882 {
1883         Object *ob= OBACT;
1884         bConstraint *con;
1885         
1886         switch(event) {
1887         case B_CONSTRAINT_TEST:
1888                 allqueue(REDRAWVIEW3D, 0);
1889                 allqueue(REDRAWBUTSOBJECT, 0);
1890                 allqueue(REDRAWBUTSEDIT, 0);
1891                 break;  // no handling
1892         case B_CONSTRAINT_INF:
1893                 /* influence; do not execute actions for 1 dag_flush */
1894                 if (ob->pose)
1895                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1896
1897         case B_CONSTRAINT_CHANGETARGET:
1898                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
1899                 DAG_scene_sort(G.scene);
1900                 break;
1901         
1902         case B_CONSTRAINT_ADD_NULL:
1903                 {
1904                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1905                         add_constraint_to_active(ob, con);
1906                         
1907                         BIF_undo_push("Add constraint");
1908                 }
1909                 break;
1910         case B_CONSTRAINT_ADD_PYTHON:
1911                 {
1912                         con = add_new_constraint(CONSTRAINT_TYPE_PYTHON);
1913                         add_constraint_to_active(ob, con);
1914                         
1915                         BIF_undo_push("Add constraint");
1916                 }
1917                 break;  
1918         case B_CONSTRAINT_ADD_KINEMATIC:
1919                 {
1920                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1921                         add_constraint_to_active(ob, con);
1922                         
1923                         BIF_undo_push("Add constraint");
1924                 }
1925                 break;
1926         case B_CONSTRAINT_ADD_CHILDOF:
1927                 {
1928                         con= add_new_constraint(CONSTRAINT_TYPE_CHILDOF);
1929                         add_constraint_to_active(ob, con);
1930                         
1931                         /* if this constraint is being added to a posechannel, make sure
1932                          * the constraint gets evaluated in pose-space
1933                          */
1934                         if (ob->flag & OB_POSEMODE) {
1935                                 con->ownspace = CONSTRAINT_SPACE_POSE;
1936                                 con->flag |= CONSTRAINT_SPACEONCE;
1937                         }
1938                         
1939                         BIF_undo_push("Add constraint");
1940                 }
1941                 break;
1942         case B_CONSTRAINT_ADD_TRACKTO:
1943                 {
1944                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1945                         add_constraint_to_active(ob, con);
1946                         
1947                         BIF_undo_push("Add constraint");
1948                 }
1949                 break;
1950         case B_CONSTRAINT_ADD_MINMAX:
1951                 {
1952                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1953                         add_constraint_to_active(ob, con);
1954                         
1955                         BIF_undo_push("Add constraint");
1956                 }
1957                 break;
1958         case B_CONSTRAINT_ADD_ROTLIKE:
1959                 {
1960                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1961                         add_constraint_to_active(ob, con);
1962                         
1963                         BIF_undo_push("Add constraint");
1964                 }
1965                 break;
1966         case B_CONSTRAINT_ADD_LOCLIKE:
1967                 {
1968                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1969                         add_constraint_to_active(ob, con);
1970                         
1971                         BIF_undo_push("Add constraint");
1972                 }
1973                 break;
1974         case B_CONSTRAINT_ADD_SIZELIKE:
1975                 {
1976                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1977                         add_constraint_to_active(ob, con);
1978                         
1979                         BIF_undo_push("Add constraint");
1980                 }
1981                 break;
1982         case B_CONSTRAINT_ADD_ACTION:
1983                 {
1984                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1985                         add_constraint_to_active(ob, con);
1986                         
1987                         BIF_undo_push("Add constraint");
1988                 }
1989                 break;
1990         case B_CONSTRAINT_ADD_LOCKTRACK:
1991                 {
1992                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1993                         add_constraint_to_active(ob, con);
1994                         
1995                         BIF_undo_push("Add constraint");
1996                 }
1997                 break;
1998         case B_CONSTRAINT_ADD_FOLLOWPATH:
1999                 {
2000                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
2001                         add_constraint_to_active(ob, con);
2002                         
2003                         BIF_undo_push("Add constraint");
2004                 }
2005                 break;
2006         case B_CONSTRAINT_ADD_STRETCHTO:
2007                 {
2008                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
2009                         add_constraint_to_active(ob, con);
2010                         
2011                         BIF_undo_push("Add constraint");
2012                 }
2013                 break;
2014         case B_CONSTRAINT_ADD_LOCLIMIT:
2015                 {
2016                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
2017                         add_constraint_to_active(ob, con);
2018                         
2019                         BIF_undo_push("Add constraint");
2020                 }
2021                 break;
2022         case B_CONSTRAINT_ADD_ROTLIMIT:
2023                 {
2024                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
2025                         add_constraint_to_active(ob, con);
2026                         
2027                         BIF_undo_push("Add constraint");
2028                 }
2029                 break;
2030         case B_CONSTRAINT_ADD_SIZELIMIT:
2031                 {
2032                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
2033                         add_constraint_to_active(ob, con);
2034                         
2035                         BIF_undo_push("Add constraint");
2036                 }
2037                 break;
2038         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
2039                 {
2040                         bRigidBodyJointConstraint *data;
2041                         Base *base_iter;
2042                         
2043                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
2044                         add_constraint_to_active(ob, con);
2045                         
2046                         /* set selected first object as target - moved from new_constraint_data */
2047                         data = (bRigidBodyJointConstraint*)con->data;
2048                         base_iter = G.scene->base.first;
2049             while ( base_iter && !data->tar ) {
2050                 if( ( ( base_iter->flag & SELECT ) &&
2051 //                     ( base_iter->lay & G.vd->lay ) ) &&
2052                     ( base_iter != G.scene->basact ) ))
2053                                 {
2054                         data->tar=base_iter->object;
2055                                                 break;
2056                                 }
2057                 base_iter = base_iter->next;
2058             }
2059                         
2060                         BIF_undo_push("Add constraint");
2061                 }
2062                 break;
2063         case B_CONSTRAINT_ADD_CLAMPTO:
2064                 {
2065                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
2066                         add_constraint_to_active(ob, con);
2067                         
2068                         BIF_undo_push("Add constraint");
2069                 }
2070                 break;
2071         case B_CONSTRAINT_ADD_TRANSFORM:
2072                 {
2073                         con = add_new_constraint(CONSTRAINT_TYPE_TRANSFORM);
2074                         add_constraint_to_active(ob, con);
2075                         
2076                         BIF_undo_push("Add constraint");
2077                 }
2078                 break;
2079         case B_CONSTRAINT_ADD_DISTLIMIT:
2080                 {
2081                         con = add_new_constraint(CONSTRAINT_TYPE_DISTLIMIT);
2082                         add_constraint_to_active(ob, con);
2083                         
2084                         BIF_undo_push("Add constraint");
2085                 }
2086                 break;
2087         case B_CONSTRAINT_ADD_SHRINKWRAP:
2088                 {
2089                         con = add_new_constraint(CONSTRAINT_TYPE_SHRINKWRAP);
2090                         add_constraint_to_active(ob, con);
2091                         
2092                         BIF_undo_push("Add constraint");
2093                 }
2094                 break;
2095
2096         default:
2097                 break;
2098         }
2099
2100         object_test_constraints(ob);
2101         
2102         if(ob->pose) update_pose_constraint_flags(ob->pose);
2103         
2104         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
2105         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2106         
2107         allqueue(REDRAWVIEW3D, 0);
2108         allqueue(REDRAWBUTSOBJECT, 0);
2109         allqueue(REDRAWBUTSEDIT, 0);
2110 }
2111
2112 void pointcache_bake(PTCacheID *pid, int startframe)
2113 {
2114         Base *base;
2115         ScrArea *sa;
2116     PointCache *cache;
2117         ListBase pidlist;
2118         float frameleno= G.scene->r.framelen;
2119         int cfrao= CFRA, didbreak =0, endframe, cstart, cend;
2120         
2121         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
2122         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
2123         G.afbreek=0; // init global break system
2124         
2125         if(pid) {
2126             cache= pid->cache;
2127
2128                 BKE_ptcache_id_time(pid, 0.0f, &cstart, &cend, NULL);
2129
2130                 startframe= startframe;
2131                 endframe= cend;
2132
2133                 cache->flag |= PTCACHE_BAKING;
2134                 cache->flag &= ~PTCACHE_BAKED;
2135         }
2136         else {
2137                 startframe= MAXFRAME;
2138                 endframe= 0;
2139
2140                 for(base=G.scene->base.first; base; base= base->next) {
2141                         if(TESTBASELIB(base)) {
2142                                 BKE_ptcache_ids_from_object(&pidlist, base->object);
2143
2144                                 for(pid=pidlist.first; pid; pid=pid->next) {
2145                                         cache= pid->cache;
2146
2147                                         BKE_ptcache_id_time(pid, 0.0f, &cstart, &cend, NULL);
2148
2149                                         startframe= MIN2(startframe, cstart);
2150                                         endframe= MAX2(endframe, cend);
2151
2152                                         cache->flag |= PTCACHE_BAKING;
2153                                         cache->flag &= ~PTCACHE_BAKED;
2154                                 }
2155
2156                                 BLI_freelistN(&pidlist);
2157                         }
2158                 }
2159         }
2160         
2161         CFRA= startframe;
2162         update_for_newframe_muted();    // put everything on this frame
2163         
2164         curarea->win_swap= 0;           // clean swapbuffers
2165         
2166         for(; CFRA <= endframe; CFRA++) {
2167                 set_timecursor(CFRA);
2168                 
2169                 update_for_newframe_muted();
2170                 
2171                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next)
2172                         if(sa->spacetype == SPACE_VIEW3D)
2173                                 scrarea_do_windraw(sa);
2174                 screen_swapbuffers();
2175
2176                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
2177                 if(blender_test_break()) {
2178                         didbreak = 1;
2179                         break;
2180                 }
2181         }
2182
2183         if(didbreak && G.qual!=LR_SHIFTKEY) {
2184                 /* failed to bake, free the frames we baked */
2185                 if(pid) {
2186                         cache= pid->cache;
2187
2188                         BKE_ptcache_id_time(pid, 0.0f, &cstart, &cend, NULL);
2189
2190                         cache->flag &= ~PTCACHE_BAKING;
2191                         BKE_ptcache_id_reset(pid, PTCACHE_RESET_OUTDATED);
2192                 }
2193                 else {
2194                         for(base=G.scene->base.first; base; base= base->next) {
2195                                 if(TESTBASELIB(base)) {
2196                                         BKE_ptcache_ids_from_object(&pidlist, base->object);
2197
2198                                         for(pid=pidlist.first; pid; pid=pid->next) {
2199                                                 cache= pid->cache;
2200
2201                                                 BKE_ptcache_id_time(pid, 0.0f, &cstart, &cend, NULL);
2202
2203                                                 cache->flag &= ~PTCACHE_BAKING;
2204
2205                                                 BKE_ptcache_id_reset(pid, PTCACHE_RESET_OUTDATED);
2206                                         }
2207
2208                                         BLI_freelistN(&pidlist);
2209                                 }
2210                         }
2211                 }
2212         }
2213         else {
2214                 /* succesfully finished baking */
2215                 if(pid) {
2216                         cache= pid->cache;
2217
2218                         cache->flag &= ~PTCACHE_BAKING;
2219                         cache->flag |= PTCACHE_BAKED;
2220                 }
2221                 else {
2222                         for(base=G.scene->base.first; base; base= base->next) {
2223                                 if(TESTBASELIB(base)) {
2224                                         BKE_ptcache_ids_from_object(&pidlist, base->object);
2225
2226                                         for(pid=pidlist.first; pid; pid=pid->next) {
2227                                                 cache= pid->cache;
2228
2229                                                 cache->flag &= ~PTCACHE_BAKING;
2230                                                 cache->flag |= PTCACHE_BAKED;
2231                                         }
2232
2233                                         BLI_freelistN(&pidlist);
2234                                 }
2235                         }
2236                 }
2237         }
2238         
2239         /* restore */
2240         waitcursor(0);
2241         sbSetInterruptCallBack(NULL); // softbody module won't ESC
2242         G.afbreek=0; // reset global break system
2243
2244         CFRA= cfrao;
2245         G.scene->r.framelen= frameleno;
2246         update_for_newframe_muted();
2247         allqueue(REDRAWVIEW3D, 0);
2248         allqueue(REDRAWBUTSOBJECT, 0);
2249 }
2250
2251 void pointcache_free(PTCacheID *pid, int cacheonly)
2252 {
2253         Base *base;
2254         ListBase pidlist;
2255         
2256         if(pid) {
2257                 if(cacheonly) {
2258                         BKE_ptcache_id_reset(pid, PTCACHE_RESET_DEPSGRAPH);
2259                 }
2260                 else {
2261                         BKE_ptcache_id_reset(pid, PTCACHE_RESET_BAKED);
2262                         pid->cache->flag &= ~PTCACHE_BAKED;
2263                 }
2264
2265                 DAG_object_flush_update(G.scene, pid->ob, OB_RECALC_DATA);
2266         }
2267         else {
2268                 for(base=G.scene->base.first; base; base= base->next) {
2269                         if(TESTBASELIB(base)) {
2270                                 BKE_ptcache_ids_from_object(&pidlist, base->object);
2271
2272                                 for(pid=pidlist.first; pid; pid=pid->next) {
2273                                         if(cacheonly) {
2274                                                 BKE_ptcache_id_reset(pid, PTCACHE_RESET_DEPSGRAPH);
2275                                         }
2276                                         else {
2277                                                 BKE_ptcache_id_reset(pid, PTCACHE_RESET_BAKED);
2278                                                 pid->cache->flag &= ~PTCACHE_BAKED;
2279                                         }
2280
2281                                         DAG_object_flush_update(G.scene, pid->ob, OB_RECALC_DATA);
2282                                 }
2283
2284                                 BLI_freelistN(&pidlist);
2285                         }
2286                 }
2287         }
2288
2289         allqueue(REDRAWVIEW3D, 0);
2290         allqueue(REDRAWBUTSOBJECT, 0);
2291 }
2292
2293 // store processed path & file prefix for fluidsim bake directory
2294 void fluidsimFilesel(char *selection)
2295 {
2296         Object *ob = OBACT;
2297         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
2298         char prefix[FILE_MAXFILE];
2299         char *srch, *srchSub, *srchExt, *lastFound;
2300         int isElbeemSurf = 0;
2301         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
2302
2303         // make prefix
2304         strcpy(srcDir, selection);
2305         BLI_splitdirstring(srcDir, srcFile);
2306         strcpy(prefix, srcFile);
2307         // check if this is a previously generated surface mesh file
2308         srch = strstr(prefix, "fluidsurface_");
2309         // TODO search from back...
2310         if(srch) {
2311                 srchSub = strstr(prefix,"_preview_");
2312                 if(!srchSub) srchSub = strstr(prefix,"_final_");
2313                 srchExt = strstr(prefix,".gz.bobj");
2314                 if(!srchExt) srchExt = strstr(prefix,".bobj");
2315                 if(srchSub && srchExt) {
2316                         *srch = '\0';
2317                         isElbeemSurf = 1;
2318                 }
2319         }
2320         if(!isElbeemSurf) {
2321                 // try to remove suffix
2322                 lastFound = NULL;
2323                 srch = strchr(prefix, '.'); // search last . from extension
2324                 while(srch) {
2325                         lastFound = srch;
2326                         if(srch) {
2327                                 srch++;
2328                                 srch = strchr(srch, '.');
2329                         }
2330                 }
2331                 if(lastFound) {
2332                         *lastFound = '\0';
2333                 } 
2334         }
2335
2336         if(fluidmd && fluidmd->fss) {
2337                 strcpy(fluidmd->fss->surfdataPath, srcDir);
2338                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
2339                 strcat(fluidmd->fss->surfdataPath, prefix);
2340
2341                 // redraw view & buttons...
2342                 allqueue(REDRAWBUTSOBJECT, 0);
2343                 allqueue(REDRAWVIEW3D, 0);
2344                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2345         }
2346 }
2347
2348 void do_object_panels(unsigned short event)
2349 {
2350         Object *ob;
2351         
2352         ob= OBACT;
2353         if(ob==NULL)
2354                 return;
2355         
2356         switch(event) {
2357         case B_TRACKBUTS:
2358                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2359                 allqueue(REDRAWVIEW3D, 0);
2360                 break;
2361         case B_RECALCPATH:
2362                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
2363                 allqueue(REDRAWVIEW3D, 0);
2364                 break;
2365         case B_DUPLI_FRAME:
2366                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
2367                 allqueue(REDRAWVIEW3D, 0);
2368                 allqueue(REDRAWBUTSOBJECT, 0);
2369                 break;
2370         case B_DUPLI_VERTS:
2371                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
2372                 DAG_scene_sort(G.scene);
2373                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
2374                 allqueue(REDRAWVIEW3D, 0);
2375                 allqueue(REDRAWBUTSOBJECT, 0);
2376                 break;
2377         case B_DUPLI_FACES:
2378                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
2379                 allqueue(REDRAWVIEW3D, 0);
2380                 allqueue(REDRAWBUTSOBJECT, 0);
2381                 break;
2382         case B_DUPLI_GROUP:
2383                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
2384                 allqueue(REDRAWVIEW3D, 0);
2385                 allqueue(REDRAWBUTSOBJECT, 0);
2386                 break;
2387                 
2388         case B_PRINTSPEED:
2389                 {
2390                         float vec[3];
2391                         CFRA++;
2392                         do_ob_ipo(ob);
2393                         where_is_object(ob);
2394                         VECCOPY(vec, ob->obmat[3]);
2395                         CFRA--;
2396                         do_ob_ipo(ob);
2397                         where_is_object(ob);
2398                         VecSubf(vec, vec, ob->obmat[3]);
2399                         prspeed= Normalize(vec);
2400                         scrarea_queue_winredraw(curarea);
2401                 }
2402                 break;
2403         case B_PRINTLEN:
2404                 if(ob->type==OB_CURVE) {
2405                         Curve *cu=ob->data;
2406                         
2407                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
2408                         scrarea_queue_winredraw(curarea);
2409                 } 
2410                 break;
2411         case B_RELKEY:
2412                 allspace(REMAKEIPO, 0);
2413                 allqueue(REDRAWBUTSOBJECT, 0);
2414                 allqueue(REDRAWBUTSEDIT, 0);
2415                 allqueue(REDRAWIPO, 0);
2416                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2417                 break;
2418         case B_CURVECHECK:
2419                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2420                 allqueue(REDRAWVIEW3D, 0);
2421                 break;
2422         
2423         case B_SOFTBODY_DEL_VG:
2424                 if(ob->soft) {
2425                         ob->soft->vertgroup= 0;
2426                         //ob->softflag |= OB_SB_REDO;
2427                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2428                         allqueue(REDRAWBUTSOBJECT, 0);
2429                         allqueue(REDRAWVIEW3D, 0);
2430                 }
2431                 break;
2432         case B_FLUIDSIM_BAKE:
2433                 /* write config files (currently no simulation) */
2434                 fluidsimBake(ob);
2435                 break;
2436         case B_FLUIDSIM_MAKEPART:
2437                 if(ob==NULL || ob->type!=OB_MESH) break;
2438                 else {
2439                         ParticleSettings *part = psys_new_settings("PSys", G.main);
2440                         ParticleSystem *psys = MEM_callocN(sizeof(ParticleSystem), "particle_system");
2441                         ModifierData *md;
2442                         ParticleSystemModifierData *psmd;
2443                         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
2444
2445                         part->type = PART_FLUID;
2446                         psys->part = part;
2447                         psys->pointcache = BKE_ptcache_add();
2448                         psys->flag |= PSYS_ENABLED;
2449
2450                         fluidmd->fss->type = OB_FLUIDSIM_PARTICLE;
2451
2452                         BLI_addtail(&ob->particlesystem,psys);
2453
2454                         md= modifier_new(eModifierType_ParticleSystem);
2455                         sprintf(md->name, "FluidParticleSystem" );
2456                         psmd= (ParticleSystemModifierData*) md;
2457                         psmd->psys=psys;
2458                         BLI_addtail(&ob->modifiers, md);
2459                 }
2460                 allqueue(REDRAWVIEW3D, 0);
2461                 allqueue(REDRAWBUTSOBJECT, 0);
2462                 break;
2463         case B_FLUIDSIM_CHANGETYPE:
2464         {
2465                 FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
2466                 fluidmd->fss->flag &= ~OB_FLUIDSIM_REVERSE; // clear flag
2467                 if(ob && ob->particlesystem.first && fluidmd->fss->type!=OB_FLUIDSIM_PARTICLE){
2468                         ParticleSystem *psys;
2469                         for(psys=ob->particlesystem.first; psys; psys=psys->next) {
2470                                 if(psys->part->type==PART_FLUID) {
2471                                         /* clear modifier */
2472                                         ParticleSystemModifierData *psmd= psys_get_modifier(ob,psys);
2473                                         BLI_remlink(&ob->modifiers, psmd);
2474                                         modifier_free((ModifierData *)psmd);
2475
2476                                         /* clear particle system */
2477                                         BLI_remlink(&ob->particlesystem,psys);
2478                                         psys_free(ob,psys);
2479
2480                                         BIF_undo_push("Delete particle system");
2481
2482                                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2483
2484                                         allqueue(REDRAWVIEW3D, 0);
2485                                         allqueue(REDRAWOOPS, 0);
2486                                         break;
2487                                 }
2488                         }
2489                 }
2490                 allqueue(REDRAWBUTSOBJECT, 0);
2491                 break;
2492         }
2493         case B_FLUIDSIM_SELDIR: 
2494                 {
2495                         ScrArea *sa = closest_bigger_area();
2496                         FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
2497                         /* choose dir for surface files */
2498                         areawinset(sa->win);
2499                         activate_fileselect(FILE_SPECIAL, "Select Directory", fluidmd->fss->surfdataPath, fluidsimFilesel);
2500                 }
2501                 break;
2502         case B_GROUP_RELINK:
2503                 group_relink_nla_objects(ob);
2504                 allqueue(REDRAWVIEW3D, 0);
2505                 break;
2506         case B_OBJECT_IPOFLAG:
2507                 if(ob->ipo) ob->ipo->showkey= (ob->ipoflag & OB_DRAWKEY)?1:0;
2508                 allqueue(REDRAWVIEW3D, 0);
2509                 break;
2510         case B_CLOTH_CHANGEPREROLL:
2511         {
2512                 ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2513                 if(clmd)
2514                 {
2515                         PTCacheID pid;
2516
2517                         BKE_ptcache_id_from_cloth(&pid, ob, clmd);
2518
2519                         // do nothing in editmode
2520                         if(pid.cache->flag & PTCACHE_BAKE_EDIT_ACTIVE)
2521                                 break;
2522                         
2523                         CFRA= 1;
2524                         update_for_newframe_muted();
2525                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2526                         allqueue(REDRAWBUTSOBJECT, 0);
2527                         allqueue(REDRAWVIEW3D, 0);
2528                 }
2529         }
2530         break;  
2531         case B_BAKE_CACHE_CHANGE:
2532         {
2533                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2534                 allqueue(REDRAWBUTSOBJECT, 0);
2535                 allqueue(REDRAWVIEW3D, 0);
2536         }
2537         break;
2538         }
2539
2540 }
2541
2542 static void do_add_groupmenu(void *arg, int event)
2543 {
2544         Object *ob= OBACT;
2545         
2546         if(ob) {
2547                 
2548                 if(event== -1) {
2549            &nbs