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