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