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