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