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