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