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