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