moved LARGEFILE defines to BLI_storage.h
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "MEM_guardedalloc.h"
43
44 #include "DNA_ID.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "BKE_action.h"
50 #include "BKE_cloth.h"
51 #include "BKE_global.h"
52 #include "BKE_main.h"
53 #include "BKE_library.h"
54 #include "BKE_softbody.h"
55 #include "BKE_utildefines.h"
56 #include "BKE_particle.h"
57
58 #include "BLI_blenlib.h"
59 #include "BLI_arithb.h"
60
61 #include "BSE_filesel.h"
62 #include "BSE_headerbuttons.h"
63
64 #include "BIF_butspace.h"
65 #include "BIF_editaction.h"
66 #include "BIF_editparticle.h"
67 #include "BIF_gl.h"
68 #include "BIF_glutil.h"
69 #include "BIF_graphics.h"
70 #include "BIF_interface.h"
71 #include "BIF_keyval.h"
72 #include "BIF_mainqueue.h"
73 #include "BIF_mywindow.h"
74 #include "BIF_poseobject.h"
75 #include "BIF_resources.h"
76 #include "BIF_screen.h"
77 #include "BIF_space.h"
78 #include "BIF_toolbox.h"
79 #include "BIF_outliner.h"
80
81 #include "BDR_drawobject.h"
82 #include "BDR_editcurve.h"
83
84 #include "mydevice.h"
85 #include "blendef.h"
86
87 /* -----includes for this file specific----- */
88
89
90 #include "DNA_action_types.h"
91 #include "DNA_armature_types.h"
92 #include "DNA_camera_types.h"
93 #include "DNA_cloth_types.h"
94 #include "DNA_constraint_types.h"
95 #include "DNA_curve_types.h"
96 #include "DNA_effect_types.h"
97 #include "DNA_group_types.h"
98 #include "DNA_image_types.h"
99 #include "DNA_key_types.h"
100 #include "DNA_lamp_types.h"
101 #include "DNA_lattice_types.h"
102 #include "DNA_material_types.h"
103 #include "DNA_meta_types.h"
104 #include "DNA_mesh_types.h"
105 #include "DNA_modifier_types.h"
106 #include "DNA_object_types.h"
107 #include "DNA_object_force.h"
108 #include "DNA_object_fluidsim.h"
109 #include "DNA_particle_types.h"
110 #include "DNA_radio_types.h"
111 #include "DNA_screen_types.h"
112 #include "DNA_sound_types.h"
113 #include "DNA_texture_types.h"
114 #include "DNA_userdef_types.h"
115 #include "DNA_vfont_types.h"
116 #include "DNA_view3d_types.h"
117 #include "DNA_world_types.h"
118 #include "DNA_text_types.h"
119
120 #include "BKE_anim.h"
121 #include "BKE_armature.h"
122 #include "BKE_constraint.h"
123 #include "BKE_curve.h"
124 #include "BKE_deform.h"
125 #include "BKE_depsgraph.h"
126 #include "BKE_displist.h"
127 #include "BKE_effect.h"
128 #include "BKE_font.h"
129 #include "BKE_group.h"
130 #include "BKE_image.h"
131 #include "BKE_ipo.h"
132 #include "BKE_lattice.h"
133 #include "BKE_material.h"
134 #include "BKE_mball.h"
135 #include "BKE_mesh.h"
136 #include "BKE_modifier.h"
137 #include "BKE_object.h"
138 #include "BKE_particle.h"
139 #include "BKE_sound.h"
140 #include "BKE_texture.h"
141 #include "BKE_utildefines.h"
142 #include "BKE_DerivedMesh.h"
143
144 #include "LBM_fluidsim.h"
145 #include "elbeem.h"
146
147 #include "BIF_editconstraint.h"
148 #include "BIF_editdeform.h"
149 #include "BIF_editparticle.h"
150
151 #include "BSE_editipo.h"
152 #include "BSE_edit.h"
153
154 #include "BDR_editobject.h"
155 #include "BPY_extern.h"
156
157 #include "butspace.h" // own module
158
159 static float prspeed=0.0;
160 float prlen=0.0;
161
162
163 /* ********************* CONSTRAINT ***************************** */
164
165 static void constraint_active_func(void *ob_v, void *con_v)
166 {
167         Object *ob= ob_v;
168         bConstraint *con;
169         ListBase *lb;
170         
171         /* lets be nice and escape if its active already */
172         if(con_v) {
173                 con= con_v;
174                 if(con->flag & CONSTRAINT_ACTIVE) return;
175         }
176         
177         lb= get_active_constraints(ob);
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 %x3|Local with Parent %x4|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 %x3|Local with Parent %x4|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, 50, 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 als 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, BUT, 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, BUT, 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, BUT, 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, BUT, 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                                 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Limit Mode%t|Inside %x0|Outside %x1|Surface %x2", *xco+((width/2)-50), *yco-104, 100, 18, &data->mode, 0, 24, 0, 0, "Distances in relation to sphere of influence to allow");
1485                         }
1486                         break;
1487                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1488                         {
1489                                 bRigidBodyJointConstraint *data = con->data;
1490                                 float extremeLin = 999.f;
1491                                 float extremeAngX = 180.f;
1492                                 float extremeAngY = 45.f;
1493                                 float extremeAngZ = 45.f;
1494                                 int togButWidth = 70;
1495                                 int offsetY = 150;
1496                                 int textButWidth = ((width/2)-togButWidth);
1497                                 
1498                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Cone Twist%x4|Generic (experimental)%x12",//|Extra Force%x6",
1499                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1500                 height = 140;
1501                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1502                                         height = 270;
1503                                 if (data->type==CONSTRAINT_RB_CONETWIST)
1504                                         height = 200;
1505                                 
1506                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1507                                 
1508                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1509                                 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");                              
1510                                 
1511                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1512                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1513                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1514                                 
1515                                 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)");
1516                                 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)");
1517                                 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)");
1518                                 
1519                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
1520                                         /* Draw Pairs of LimitToggle+LimitValue */
1521                                         uiBlockBeginAlign(block); 
1522                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1523                                                 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"); 
1524                                         uiBlockEndAlign(block);
1525                                         
1526                                         uiBlockBeginAlign(block); 
1527                                                 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"); 
1528                                                 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"); 
1529                                         uiBlockEndAlign(block);
1530                                         
1531                                         offsetY += 20;
1532                                         uiBlockBeginAlign(block); 
1533                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1534                                                 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"); 
1535                                         uiBlockEndAlign(block);
1536                                         
1537                                         uiBlockBeginAlign(block); 
1538                                                 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"); 
1539                                                 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"); 
1540                                         uiBlockEndAlign(block);
1541                                         
1542                                         offsetY += 20;
1543                                         uiBlockBeginAlign(block); 
1544                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1545                                                 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"); 
1546                                         uiBlockEndAlign(block);
1547                                         
1548                                         uiBlockBeginAlign(block); 
1549                                                 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"); 
1550                                                 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"); 
1551                                         uiBlockEndAlign(block);
1552                                         offsetY += 20;
1553                                 }
1554                                 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
1555                                         /* Draw Pairs of LimitToggle+LimitValue */
1556                                         uiBlockBeginAlign(block); 
1557                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1558                                                 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"); 
1559                                         uiBlockEndAlign(block);
1560                                         uiBlockBeginAlign(block); 
1561                                                 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"); 
1562                                                 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"); 
1563                                         uiBlockEndAlign(block);
1564                                         
1565                                         offsetY += 20;
1566                                         uiBlockBeginAlign(block); 
1567                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1568                                                 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"); 
1569                                         uiBlockEndAlign(block);
1570                                         
1571                                         uiBlockBeginAlign(block); 
1572                                                 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"); 
1573                                                 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"); 
1574                                         uiBlockEndAlign(block);
1575                                         
1576                                         offsetY += 20;
1577                                         uiBlockBeginAlign(block); 
1578                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1579                                                 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"); 
1580                                         uiBlockEndAlign(block);
1581                                         
1582                                         uiBlockBeginAlign(block); 
1583                                                 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"); 
1584                                                 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"); 
1585                                         uiBlockEndAlign(block);
1586                                 }
1587                         }
1588                         break;
1589                 case CONSTRAINT_TYPE_CLAMPTO:
1590                         {
1591                                 bClampToConstraint *data = con->data;
1592                                 
1593                                 height = 90;
1594                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1595                                 
1596                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1597                                 
1598                                 /* Draw target parameters */
1599                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1600                                 
1601                                 /* Draw XYZ toggles */
1602                                 uiBlockBeginAlign(block);
1603                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1604                                         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");
1605                                         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");
1606                                         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");
1607                                         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");
1608                                 uiBlockEndAlign(block);
1609                                 
1610                                 /* Extra Options Controlling Behaviour */
1611                                 //uiBlockBeginAlign(block);
1612                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Options:", *xco, *yco-88, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1613                                         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)");
1614                                 //uiBlockEndAlign(block);
1615                         }
1616                         break;
1617                 case CONSTRAINT_TYPE_TRANSFORM:
1618                         {
1619                                 bTransformConstraint *data = con->data;
1620                                 float fmin, fmax, tmin, tmax;
1621                                 
1622                                 height = 178;
1623                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1624                                 
1625                                 /* Draw target parameters */                    
1626                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1627                                 
1628                                 /* Draw target parameters */
1629                                 uiBlockBeginAlign(block);
1630                                         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"); 
1631                                         
1632                                         if (is_armature_target(data->tar)) {
1633                                                 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");
1634                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1635                                         }
1636                                         else if (is_geom_target(data->tar)) {
1637                                                 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");
1638                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)data->tar);
1639                                         }
1640                                         else {
1641                                                 strcpy(data->subtarget, "");
1642                                         }
1643                                 uiBlockEndAlign(block);
1644                                 
1645                                 /* Extrapolate Ranges? */
1646                                 uiDefButBitC(block, TOG, 1, B_CONSTRAINT_TEST, "Extrapolate", *xco, *yco-42,80,19, &data->expo, 0, 0, 0, 0, "Extrapolate ranges");
1647                                 
1648                                 /* Draw options for source motion */
1649                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Source:", *xco-10, *yco-62, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1650                                 
1651                                 /*      draw Loc/Rot/Size toggles       */
1652                                 uiBlockBeginAlign(block);
1653                                         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");
1654                                         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");
1655                                         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");
1656                                 uiBlockEndAlign(block);
1657                                 
1658                                 /* Draw Pairs of Axis: Min/Max Value*/
1659                                 if (data->from == 2) {
1660                                         fmin= 0.0001;
1661                                         fmax= 1000.0;
1662                                 }
1663                                 else if (data->from == 1) {
1664                                         fmin= -360.0;
1665                                         fmax= 360.0;
1666                                 }
1667                                 else {
1668                                         fmin = -1000.0;
1669                                         fmax= 1000.0;
1670                                 }
1671                                 
1672                                 uiBlockBeginAlign(block); 
1673                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "X:", *xco-10, *yco-107, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1674                                         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"); 
1675                                         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"); 
1676                                 uiBlockEndAlign(block); 
1677                                 
1678                                 uiBlockBeginAlign(block); 
1679                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Y:", *xco-10, *yco-127, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1680                                         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"); 
1681                                         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"); 
1682                                 uiBlockEndAlign(block);
1683                                 
1684                                 uiBlockBeginAlign(block); 
1685                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Z:", *xco-10, *yco-147, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1686                                         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"); 
1687                                         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"); 
1688                                 uiBlockEndAlign(block); 
1689                                 
1690                                 
1691                                 /* Draw options for target motion */
1692                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Destination:", *xco+150, *yco-62, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1693                                 
1694                                 /*      draw Loc/Rot/Size toggles       */
1695                                 uiBlockBeginAlign(block);
1696                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Loc", *xco+150, *yco-82, 45, 18, &data->to, 12.0, 0, 0, 0, "Use as Location transform");
1697                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Rot", *xco+195, *yco-82, 45, 18, &data->to, 12.0, 1, 0, 0, "Use as Rotation transform");
1698                                         uiDefButS(block, ROW, B_CONSTRAINT_TEST, "Scale", *xco+245, *yco-82, 45, 18, &data->to, 12.0, 2, 0, 0, "Use as Scale transform");
1699                                 uiBlockEndAlign(block);
1700                                 
1701                                 /* Draw Pairs of Source-Axis: Min/Max Value*/
1702                                 if (data->to == 2) {
1703                                         tmin= 0.0001;
1704                                         tmax= 1000.0;
1705                                 }
1706                                 else if (data->to == 1) {
1707                                         tmin= -360.0;
1708                                         tmax= 360.0;
1709                                 }
1710                                 else {
1711                                         tmin = -1000.0;
1712                                         tmax= 1000.0;
1713                                 }
1714                                 
1715                                 uiBlockBeginAlign(block); 
1716                                         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");
1717                                         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"); 
1718                                         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"); 
1719                                 uiBlockEndAlign(block); 
1720                                 
1721                                 uiBlockBeginAlign(block); 
1722                                         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");
1723                                         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"); 
1724                                         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"); 
1725                                 uiBlockEndAlign(block);
1726                                 
1727                                 uiBlockBeginAlign(block); 
1728                                         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");
1729                                         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"); 
1730                                         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"); 
1731                                 uiBlockEndAlign(block); 
1732                                 
1733                                 /* constraint space settings */
1734                                 draw_constraint_spaceselect(block, con, *xco, *yco-170, is_armature_owner(ob), is_armature_target(data->tar));
1735                         }
1736                         break;
1737                 case CONSTRAINT_TYPE_NULL:
1738                         {
1739                                 height = 17;
1740                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1741                         }
1742                         break;
1743                 default:
1744                         height = 0;
1745                         break;
1746                 }
1747                 
1748                 (*yco)-=(24+height);
1749         }
1750
1751         if (ELEM(con->type, CONSTRAINT_TYPE_NULL, CONSTRAINT_TYPE_RIGIDBODYJOINT)==0) {
1752                 uiBlockBeginAlign(block);
1753                 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");
1754                 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");
1755                 /* If this is on an object or bone, add ipo channel the constraint */
1756                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1757                 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");
1758                 /* Add a keyframe to the influence IPO */
1759                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1760                 uiBlockEndAlign(block);
1761                 (*yco)-=24;
1762         } 
1763         else {
1764                 (*yco)-=3;
1765         }
1766         
1767         /* clear any locks set up for proxies/lib-linking */
1768         uiClearButLock();
1769 }
1770
1771 static uiBlock *add_constraintmenu(void *arg_unused)
1772 {
1773         Object *ob= OBACT;
1774         uiBlock *block;
1775         ListBase *conlist;
1776         short yco= 0;
1777         
1778         conlist = get_active_constraints(ob);
1779         
1780         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1781
1782         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CHILDOF, "Child Of",                     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1783         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRANSFORM, "Transformation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1784         
1785         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1786         
1787         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE, "Copy Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1788         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE, "Copy Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1789         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE, "Copy Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1790         
1791         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1792         
1793         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT, "Limit Location", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1794         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT, "Limit Rotation", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1795         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT, "Limit Scale", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1796         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_DISTLIMIT, "Limit Distance", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1797         
1798         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1799         
1800         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO, "Track To",     0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1801         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX, "Floor", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1802         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK, "Locked Track", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1803         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH, "Follow Path", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1804                 
1805         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1806         
1807         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO, "Clamp To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1808         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO, "Stretch To", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1809
1810         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT, "Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1811
1812         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1813         
1814         if (ob->flag & OB_POSEMODE) {
1815                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC, "IK Solver", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1816         }
1817         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION, "Action", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1818         
1819         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1820
1821         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_PYTHON, "Script", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1822         
1823         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1824         
1825         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL, "Null",    0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1826         
1827         
1828         uiTextBoundsBlock(block, 50);
1829         uiBlockSetDirection(block, UI_DOWN);
1830                 
1831         return block;
1832 }
1833
1834 void do_constraintbuts(unsigned short event)
1835 {
1836         Object *ob= OBACT;
1837         bConstraint *con;
1838         
1839         switch(event) {
1840         case B_CONSTRAINT_TEST:
1841                 break;  // no handling
1842         case B_CONSTRAINT_INF:
1843                 /* influence; do not execute actions for 1 dag_flush */
1844                 if (ob->pose)
1845                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1846
1847         case B_CONSTRAINT_CHANGETARGET:
1848                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
1849                 DAG_scene_sort(G.scene);
1850                 break;
1851         
1852         case B_CONSTRAINT_ADD_NULL:
1853                 {
1854                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1855                         add_constraint_to_active(ob, con);
1856                         
1857                         BIF_undo_push("Add constraint");
1858                 }
1859                 break;
1860         case B_CONSTRAINT_ADD_PYTHON:
1861                 {
1862                         con = add_new_constraint(CONSTRAINT_TYPE_PYTHON);
1863                         add_constraint_to_active(ob, con);
1864                         
1865                         BIF_undo_push("Add constraint");
1866                 }
1867                 break;  
1868         case B_CONSTRAINT_ADD_KINEMATIC:
1869                 {
1870                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1871                         add_constraint_to_active(ob, con);
1872                         
1873                         BIF_undo_push("Add constraint");
1874                 }
1875                 break;
1876         case B_CONSTRAINT_ADD_CHILDOF:
1877                 {
1878                         con= add_new_constraint(CONSTRAINT_TYPE_CHILDOF);
1879                         add_constraint_to_active(ob, con);
1880                         
1881                         /* if this constraint is being added to a posechannel, make sure
1882                          * the constraint gets evaluated in pose-space
1883                          */
1884                         if (ob->flag & OB_POSEMODE) {
1885                                 con->ownspace = CONSTRAINT_SPACE_POSE;
1886                                 con->flag |= CONSTRAINT_SPACEONCE;
1887                         }
1888                         
1889                         BIF_undo_push("Add constraint");
1890                 }
1891                 break;
1892         case B_CONSTRAINT_ADD_TRACKTO:
1893                 {
1894                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1895                         add_constraint_to_active(ob, con);
1896                         
1897                         BIF_undo_push("Add constraint");
1898                 }
1899                 break;
1900         case B_CONSTRAINT_ADD_MINMAX:
1901                 {
1902                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1903                         add_constraint_to_active(ob, con);
1904                         
1905                         BIF_undo_push("Add constraint");
1906                 }
1907                 break;
1908         case B_CONSTRAINT_ADD_ROTLIKE:
1909                 {
1910                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1911                         add_constraint_to_active(ob, con);
1912                         
1913                         BIF_undo_push("Add constraint");
1914                 }
1915                 break;
1916         case B_CONSTRAINT_ADD_LOCLIKE:
1917                 {
1918                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1919                         add_constraint_to_active(ob, con);
1920                         
1921                         BIF_undo_push("Add constraint");
1922                 }
1923                 break;
1924         case B_CONSTRAINT_ADD_SIZELIKE:
1925                 {
1926                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1927                         add_constraint_to_active(ob, con);
1928                         
1929                         BIF_undo_push("Add constraint");
1930                 }
1931                 break;
1932         case B_CONSTRAINT_ADD_ACTION:
1933                 {
1934                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1935                         add_constraint_to_active(ob, con);
1936                         
1937                         BIF_undo_push("Add constraint");
1938                 }
1939                 break;
1940         case B_CONSTRAINT_ADD_LOCKTRACK:
1941                 {
1942                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1943                         add_constraint_to_active(ob, con);
1944                         
1945                         BIF_undo_push("Add constraint");
1946                 }
1947                 break;
1948         case B_CONSTRAINT_ADD_FOLLOWPATH:
1949                 {
1950                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1951                         add_constraint_to_active(ob, con);
1952                         
1953                         BIF_undo_push("Add constraint");
1954                 }
1955                 break;
1956         case B_CONSTRAINT_ADD_STRETCHTO:
1957                 {
1958                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1959                         add_constraint_to_active(ob, con);
1960                         
1961                         BIF_undo_push("Add constraint");
1962                 }
1963                 break;
1964         case B_CONSTRAINT_ADD_LOCLIMIT:
1965                 {
1966                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
1967                         add_constraint_to_active(ob, con);
1968                         
1969                         BIF_undo_push("Add constraint");
1970                 }
1971                 break;
1972         case B_CONSTRAINT_ADD_ROTLIMIT:
1973                 {
1974                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
1975                         add_constraint_to_active(ob, con);
1976                         
1977                         BIF_undo_push("Add constraint");
1978                 }
1979                 break;
1980         case B_CONSTRAINT_ADD_SIZELIMIT:
1981                 {
1982                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
1983                         add_constraint_to_active(ob, con);
1984                         
1985                         BIF_undo_push("Add constraint");
1986                 }
1987                 break;
1988         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
1989                 {
1990                         bRigidBodyJointConstraint *data;
1991                         Base *base_iter;
1992                         
1993                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
1994                         add_constraint_to_active(ob, con);
1995                         
1996                         /* set selected first object as target - moved from new_constraint_data */
1997                         data = (bRigidBodyJointConstraint*)con->data;
1998                         base_iter = G.scene->base.first;
1999             while ( base_iter && !data->tar ) {
2000                 if( ( ( base_iter->flag & SELECT ) &&
2001 //                     ( base_iter->lay & G.vd->lay ) ) &&
2002                     ( base_iter != G.scene->basact ) ))
2003                                 {
2004                         data->tar=base_iter->object;
2005                                                 break;
2006                                 }
2007                 base_iter = base_iter->next;
2008             }
2009                         
2010                         BIF_undo_push("Add constraint");
2011                 }
2012                 break;
2013         case B_CONSTRAINT_ADD_CLAMPTO:
2014                 {
2015                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
2016                         add_constraint_to_active(ob, con);
2017                         
2018                         BIF_undo_push("Add constraint");
2019                 }
2020                 break;
2021         case B_CONSTRAINT_ADD_TRANSFORM:
2022                 {
2023                         con = add_new_constraint(CONSTRAINT_TYPE_TRANSFORM);
2024                         add_constraint_to_active(ob, con);
2025                         
2026                         BIF_undo_push("Add constraint");
2027                 }
2028                 break;
2029         case B_CONSTRAINT_ADD_DISTLIMIT:
2030                 {
2031                         con = add_new_constraint(CONSTRAINT_TYPE_DISTLIMIT);
2032                         add_constraint_to_active(ob, con);
2033                         
2034                         BIF_undo_push("Add constraint");
2035                 }
2036                 break;
2037
2038         default:
2039                 break;
2040         }
2041
2042         object_test_constraints(ob);
2043         
2044         if(ob->pose) update_pose_constraint_flags(ob->pose);
2045         
2046         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
2047         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2048         
2049         allqueue (REDRAWVIEW3D, 0);
2050         allqueue (REDRAWBUTSOBJECT, 0);
2051 }
2052
2053 void softbody_bake(Object *ob)
2054 {
2055         Base *base;
2056         SoftBody *sb;
2057         ScrArea *sa;
2058         float frameleno= G.scene->r.framelen;
2059         int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
2060         
2061         
2062         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
2063         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
2064         G.afbreek=0; // init global break system
2065         
2066         if(ob) {
2067                 sb= ob->soft;
2068                 sfra= MIN2(sfra, sb->sfra);
2069                 efra= MAX2(efra, sb->efra);
2070                 sbObjectToSoftbody(ob); // put softbody in restposition, free bake
2071                 ob->softflag |= OB_SB_BAKEDO;
2072         }
2073         else {
2074                 for(base=G.scene->base.first; base; base= base->next) {
2075                         if(TESTBASELIB(base)) {
2076                                 if(base->object->soft) {
2077                                         sb= base->object->soft;
2078                                         sfra= MIN2(sfra, sb->sfra);
2079                                         efra= MAX2(efra, sb->efra);
2080                                         sbObjectToSoftbody(base->object);       // put softbody in restposition, free bake
2081                                         base->object->softflag |= OB_SB_BAKEDO;
2082                                 }
2083                         }
2084                 }
2085         }
2086         
2087         CFRA= sfra;
2088         update_for_newframe_muted();    // put everything on this frame
2089         
2090         curarea->win_swap= 0;           // clean swapbuffers
2091         
2092         for(; CFRA <= efra; CFRA++) {
2093                 set_timecursor(CFRA);
2094                 
2095                 update_for_newframe_muted();
2096                 
2097                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
2098                         if(sa->spacetype == SPACE_VIEW3D) {
2099                                 scrarea_do_windraw(sa);
2100                         }
2101                 }
2102                 screen_swapbuffers();
2103                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
2104                 if (blender_test_break()){ 
2105                         didbreak = 1;
2106                         break;
2107                 }
2108
2109         }
2110         if((didbreak)&&(G.qual!=LR_SHIFTKEY)) {
2111                 if(ob) 
2112                         sbObjectToSoftbody(ob); // free bake
2113                 else {
2114                         for(base=G.scene->base.first; base; base= base->next) {
2115                                 if(TESTBASELIB(base)) {
2116                                         if(base->object->soft) {
2117                                                 sbObjectToSoftbody(base->object);       // free bake
2118                                         }
2119                                 }
2120                         }
2121                 }
2122         }
2123         
2124         /* restore */
2125         waitcursor(0);
2126         sbSetInterruptCallBack(NULL); // softbody module won't ESC
2127         G.afbreek=0; // reset global break system
2128         
2129         if(ob) 
2130                 ob->softflag &= ~OB_SB_BAKEDO;
2131         else {
2132                 for(base=G.scene->base.first; base; base= base->next)
2133                         if(TESTBASELIB(base))
2134                                 if(base->object->soft)
2135                                         base->object->softflag &= ~OB_SB_BAKEDO;
2136         }
2137         
2138         CFRA= cfrao;
2139         G.scene->r.framelen= frameleno;
2140         update_for_newframe_muted();
2141         allqueue(REDRAWVIEW3D, 0);
2142         allqueue(REDRAWBUTSOBJECT, 0);
2143 }
2144
2145 // store processed path & file prefix for fluidsim bake directory
2146 void fluidsimFilesel(char *selection)
2147 {
2148         Object *ob = OBACT;
2149         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
2150         char prefix[FILE_MAXFILE];
2151         char *srch, *srchSub, *srchExt, *lastFound;
2152         int isElbeemSurf = 0;
2153
2154         // make prefix
2155         strcpy(srcDir, selection);
2156         BLI_splitdirstring(srcDir, srcFile);
2157         strcpy(prefix, srcFile);
2158         // check if this is a previously generated surface mesh file
2159         srch = strstr(prefix, "fluidsurface_");
2160         // TODO search from back...
2161         if(srch) {
2162                 srchSub = strstr(prefix,"_preview_");
2163                 if(!srchSub) srchSub = strstr(prefix,"_final_");
2164                 srchExt = strstr(prefix,".gz.bobj");
2165                 if(!srchExt) srchExt = strstr(prefix,".bobj");
2166                 if(srchSub && srchExt) {
2167                         *srch = '\0';
2168                         isElbeemSurf = 1;
2169                 }
2170         }
2171         if(!isElbeemSurf) {
2172                 // try to remove suffix
2173                 lastFound = NULL;
2174                 srch = strchr(prefix, '.'); // search last . from extension
2175                 while(srch) {
2176                         lastFound = srch;
2177                         if(srch) {
2178                                 srch++;
2179                                 srch = strchr(srch, '.');
2180                         }
2181                 }
2182                 if(lastFound) {
2183                         *lastFound = '\0';
2184                 } 
2185         }
2186
2187         if(ob->fluidsimSettings) {
2188                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
2189                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
2190                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
2191
2192                 // redraw view & buttons...
2193                 allqueue(REDRAWBUTSOBJECT, 0);
2194                 allqueue(REDRAWVIEW3D, 0);
2195                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2196         }
2197 }
2198
2199 void do_object_panels(unsigned short event)
2200 {
2201         Object *ob;
2202         Effect *eff;
2203         
2204         ob= OBACT;
2205         if(ob==NULL)
2206                 return;
2207         
2208         switch(event) {
2209         case B_TRACKBUTS:
2210                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2211                 allqueue(REDRAWVIEW3D, 0);
2212                 break;
2213         case B_RECALCPATH:
2214                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
2215                 allqueue(REDRAWVIEW3D, 0);
2216                 break;
2217         case B_DUPLI_FRAME:
2218                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
2219                 allqueue(REDRAWVIEW3D, 0);
2220                 allqueue(REDRAWBUTSOBJECT, 0);
2221                 break;
2222         case B_DUPLI_VERTS:
2223                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
2224                 DAG_scene_sort(G.scene);
2225                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
2226                 allqueue(REDRAWVIEW3D, 0);
2227                 allqueue(REDRAWBUTSOBJECT, 0);
2228                 break;
2229         case B_DUPLI_FACES:
2230                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
2231                 allqueue(REDRAWVIEW3D, 0);
2232                 allqueue(REDRAWBUTSOBJECT, 0);
2233                 break;
2234         case B_DUPLI_GROUP:
2235                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
2236                 allqueue(REDRAWVIEW3D, 0);
2237                 allqueue(REDRAWBUTSOBJECT, 0);
2238                 break;
2239                 
2240         case B_PRINTSPEED:
2241                 {
2242                         float vec[3];
2243                         CFRA++;
2244                         do_ob_ipo(ob);
2245                         where_is_object(ob);
2246                         VECCOPY(vec, ob->obmat[3]);
2247                         CFRA--;
2248                         do_ob_ipo(ob);
2249                         where_is_object(ob);
2250                         VecSubf(vec, vec, ob->obmat[3]);
2251                         prspeed= Normalize(vec);
2252                         scrarea_queue_winredraw(curarea);
2253                 }
2254                 break;
2255         case B_PRINTLEN:
2256                 if(ob->type==OB_CURVE) {
2257                         Curve *cu=ob->data;
2258                         
2259                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
2260                         scrarea_queue_winredraw(curarea);
2261                 } 
2262                 break;
2263         case B_RELKEY:
2264                 allspace(REMAKEIPO, 0);
2265                 allqueue(REDRAWBUTSOBJECT, 0);
2266                 allqueue(REDRAWBUTSEDIT, 0);
2267                 allqueue(REDRAWIPO, 0);
2268                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2269                 break;
2270         case B_CURVECHECK:
2271                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2272                 allqueue(REDRAWVIEW3D, 0);
2273                 break;
2274         
2275         case B_SOFTBODY_CHANGE:
2276                 ob= OBACT;
2277                 if(ob) {
2278                         ParticleSystem *psys = PE_get_current(ob);
2279                         if(psys)
2280                                 psys->softflag |= OB_SB_REDO;
2281                         else
2282                                 ob->softflag |= OB_SB_REDO;
2283                         allqueue(REDRAWBUTSOBJECT, 0);
2284                         allqueue(REDRAWVIEW3D, 0);
2285                 }
2286                 break;
2287         case B_SOFTBODY_DEL_VG:
2288                 if(ob->soft) {
2289                         ob->soft->vertgroup= 0;
2290                         ob->softflag |= OB_SB_REDO;
2291                         allqueue(REDRAWBUTSOBJECT, 0);
2292                         allqueue(REDRAWVIEW3D, 0);
2293                 }
2294                 break;
2295         case B_SOFTBODY_BAKE:
2296                 if(ob->soft) softbody_bake(ob);
2297                 break;
2298         case B_SOFTBODY_BAKE_FREE:
2299                 if(ob->soft) sbObjectToSoftbody(ob);
2300                 allqueue(REDRAWBUTSOBJECT, 0);
2301                 allqueue(REDRAWVIEW3D, 0);
2302                 break;
2303         case B_FLUIDSIM_BAKE:
2304                 /* write config files (currently no simulation) */
2305                 fluidsimBake(ob);
2306                 break;
2307         case B_FLUIDSIM_MAKEPART:
2308                 {
2309                         PartEff *paf= NULL;
2310                         /* prepare fluidsim particle display */
2311                         // simplified delete effect, create new - recalc some particles...
2312                         if(ob==NULL || ob->type!=OB_MESH) break;
2313                         ob->fluidsimSettings->type = 0;
2314                         // reset type, and init particle system once normally
2315                         paf= give_parteff(ob); 
2316                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
2317                             (!paf)) { 
2318                                 // create new entry
2319                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
2320                         paf = give_parteff(ob);
2321                         if(paf) {
2322                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
2323                                 build_particle_system(ob);
2324                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
2325                         }
2326                 }
2327                 allqueue(REDRAWVIEW3D, 0);
2328                 allqueue(REDRAWBUTSOBJECT, 0);
2329                 break;
2330         case B_FLUIDSIM_SELDIR: 
2331                 {
2332                         ScrArea *sa = closest_bigger_area();
2333                         /* choose dir for surface files */
2334                         areawinset(sa->win);
2335                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
2336                 }
2337                 break;
2338         case B_FLUIDSIM_FORCEREDRAW:
2339                 /* force redraw */
2340                 allqueue(REDRAWBUTSOBJECT, 0);
2341                 allqueue(REDRAWVIEW3D, 0);
2342                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2343                 break;
2344         case B_GROUP_RELINK:
2345                 group_relink_nla_objects(ob);
2346                 allqueue(REDRAWVIEW3D, 0);
2347                 break;
2348         case B_BAKEABLE_CHANGE:
2349                 allqueue(REDRAWBUTSOBJECT, 0);
2350                 allqueue(REDRAWVIEW3D, 0);
2351                 break;
2352         case B_OBJECT_IPOFLAG:
2353                 if(ob->ipo) ob->ipo->showkey= (ob->ipoflag & OB_DRAWKEY)?1:0;
2354                 allqueue(REDRAWVIEW3D, 0);
2355                 break;
2356         case B_CLOTH_CLEARCACHEALL:
2357         {
2358                 ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2359                 if(clmd)
2360                 {
2361                         // do nothing in editmode
2362                         if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE)
2363                                 break;
2364                         
2365                         /* force freeing because user wants */
2366                         clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
2367                         
2368                         /*user wants to free all, so free whole cloth, this helps to start sim at later frame */
2369                         clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
2370                         
2371                         CFRA= 1;
2372                         update_for_newframe_muted();
2373                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2374                         cloth_clear_cache(ob, clmd, 0); 
2375                         allqueue(REDRAWBUTSOBJECT, 0);
2376                         allqueue(REDRAWVIEW3D, 0);
2377                 }       
2378         }
2379         break;  
2380         case B_CLOTH_CLEARCACHEFRAME:
2381         {
2382                 ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2383                 if(clmd)
2384                 {
2385                         // do nothing in editmode
2386                         if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE)
2387                                 break;
2388                         
2389                         /* force freeing because user wants */
2390                         clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
2391                         
2392                         cloth_clear_cache(ob, clmd, MAX2(0.0,G.scene->r.cfra)); 
2393                         // MAX2(1.0,G.scene->r.cfra + 1.0)
2394                         allqueue(REDRAWBUTSOBJECT, 0);
2395                 }
2396         }
2397         break;  
2398         case B_CLOTH_CHANGEPREROLL:
2399         {
2400                 ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2401                 if(clmd)
2402                 {
2403                         // do nothing in editmode
2404                         if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE)
2405                                 break;
2406                         
2407                         CFRA= 1;
2408                         update_for_newframe_muted();
2409                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2410                         allqueue(REDRAWBUTSOBJECT, 0);
2411                         allqueue(REDRAWVIEW3D, 0);
2412                 }
2413         }
2414         break;  
2415         case B_CLOTH_RENEW:
2416         {
2417                 ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
2418         
2419                 if(clmd)
2420                 {
2421                         clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
2422                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
2423                         allqueue(REDRAWBUTSOBJECT, 0);
2424                         allqueue(REDRAWVIEW3D, 0);
2425                 }
2426         }
2427         break;
2428                 
2429         default:
2430                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2431                         int a=B_SELEFFECT;
2432                         
2433                         eff= ob->effect.first;
2434                         while(eff) {
2435                                 if(event==a) eff->flag |= SELECT;
2436                                 else eff->flag &= ~SELECT;
2437                                 
2438                                 a++;
2439                                 eff= eff->next;
2440                         }
2441                         allqueue(REDRAWBUTSOBJECT, 0);
2442                 }
2443         }
2444
2445 }
2446
2447 static void do_add_groupmenu(void *arg, int event)
2448 {
2449         Object *ob= OBACT;
2450         
2451         if(ob) {
2452                 
2453                 if(event== -1) {
2454                         Group *group= add_group( "Group" );
2455                         add_to_group(group, ob);
2456                 }
2457                 else
2458                         add_to_group(BLI_findlink(&G.main->group, event), ob);
2459                         
2460                 ob->flag |= OB_FROMGROUP;
2461                 BASACT->flag |= OB_FROMGROUP;
2462                 allqueue(REDRAWBUTSOBJECT, 0);
2463                 allqueue(REDRAWVIEW3D, 0);
2464         }               
2465 }
2466
2467 static uiBlock *add_groupmenu(void *arg_unused)
2468 {
2469         uiBlock *block;
2470         Group *group;
2471         short yco= 0;
2472         char str[32];
2473         
2474         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
2475         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
2476
2477         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
2478         for(group= G.main->group.first; group; group= group->id.next, yco++) {
2479                 if(group->id.lib) strcpy(str, "L  ");
2480                 else strcpy(str, "   ");
2481                 strcat(str, group->id.name+2);
2482                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
2483         }
2484         
2485         uiTextBoundsBlock(block, 50);
2486         uiBlockSetDirection(block, UI_DOWN);    
2487         
2488         return block;
2489 }
2490
2491 static void group_ob_rem(void *gr_v, void *ob_v)
2492 {
2493         Object *ob= OBACT;
2494         
2495         if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) {
2496                 ob->flag &= ~OB_FROMGROUP;
2497                 BASACT->flag &= ~OB_FROMGROUP;
2498         }
2499         allqueue(REDRAWBUTSOBJECT, 0);
2500         allqueue(REDRAWVIEW3D, 0);
2501
2502 }
2503
2504 static void group_local(void *gr_v, void *unused)
2505 {
2506         Group *group= gr_v;
2507         
2508         group->id.lib= NULL;
2509         
2510         allqueue(REDRAWBUTSOBJECT, 0);
2511         allqueue(REDRAWVIEW3D, 0);
2512         
2513 }
2514
2515 static void object_panel_object(Object *ob)
2516 {
2517         uiBlock *block;
2518         uiBut *but;
2519         Group *group;
2520         int a, xco, yco=0;
2521         short dx= 33, dy= 30;
2522         int is_libdata = object_is_libdata(ob);
2523         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
2524         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
2525         
2526         
2527         
2528         /* object name */
2529         uiBlockSetCol(block, TH_BUT_SETTING2);
2530         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2531         xco= std_libbuttons(block, 10, 180, 0, NULL, 0, ID_OB, 0, &ob->id, NULL, &(G.buts->menunr), B_OBALONE, B_OBLOCAL, 0, 0, B_KEEPDATA);
2532         uiBlockSetCol(block, TH_AUTO);
2533         
2534         /* parent */
2535         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2536         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
2537         
2538         uiSetButLock(is_libdata, ERROR_LIBDATA_MESSAGE);
2539         but = uiDefButS(block, NUM, B_NOP, "PassIndex:",                xco+5, 150, 305-xco, 20, &ob->index, 0.0, 1000.0, 0, 0, "Index # for the IndexOB render pass.");
2540         
2541         uiSetButLock(1, NULL);
2542         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
2543
2544         /* all groups */
2545         for(group= G.main->group.first; group; group= group->id.next) {
2546                 if(object_in_group(ob, group)) {
2547                         xco= 160;
2548                         
2549                         uiBlockBeginAlign(block);
2550                         but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 150, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
2551                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
2552                         
2553                         if(group->id.lib) {
2554                                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 160, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
2555                                 uiButSetFunc(but, group_local, group, NULL);
2556                                 xco= 180;
2557                         }
2558                         but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
2559                         uiButSetFunc(but, group_ob_rem, group, ob);
2560                         
2561                         yco+= 20;
2562                         xco= 10;
2563