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