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