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