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