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