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