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