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