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