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