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