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