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