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