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