== Transformation Constraint ==
[blender-staging.git] / source / blender / python / api2_2x / Constraint.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  * This is a new part of Blender.
27  *
28  * Contributor(s): Joseph Gilbert, Ken Hughes, Joshua Leung
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include "Constraint.h" /*This must come first*/
34
35 #include "DNA_object_types.h"
36 #include "DNA_effect_types.h"
37 #include "DNA_vec_types.h"
38 #include "DNA_curve_types.h"
39 #include "DNA_text_types.h"
40
41 #include "BKE_main.h"
42 #include "BKE_global.h"
43 #include "BKE_library.h"
44 #include "BKE_action.h"
45 #include "BKE_armature.h"
46 #include "BLI_blenlib.h"
47 #include "BIF_editconstraint.h"
48 #include "BSE_editipo.h"
49 #include "MEM_guardedalloc.h"
50 #include "butspace.h"
51 #include "blendef.h"
52 #include "mydevice.h"
53
54 #include "IDProp.h"
55 #include "Object.h"
56 #include "NLA.h"
57 #include "Text.h"
58 #include "gen_utils.h"
59
60 enum constraint_constants {
61         EXPP_CONSTR_XROT = 0,
62         EXPP_CONSTR_YROT = 1,
63         EXPP_CONSTR_ZROT = 2,
64         EXPP_CONSTR_XSIZE = 10,
65         EXPP_CONSTR_YSIZE = 11,
66         EXPP_CONSTR_ZSIZE = 12,
67         EXPP_CONSTR_XLOC = 20,
68         EXPP_CONSTR_YLOC = 21,
69         EXPP_CONSTR_ZLOC = 22,
70
71         EXPP_CONSTR_MAXX = TRACK_X,
72         EXPP_CONSTR_MAXY = TRACK_Y,
73         EXPP_CONSTR_MAXZ = TRACK_Z,
74         EXPP_CONSTR_MINX = TRACK_nX,
75         EXPP_CONSTR_MINY = TRACK_nY,
76         EXPP_CONSTR_MINZ = TRACK_nZ,
77
78         EXPP_CONSTR_TARGET = 100,
79         EXPP_CONSTR_STRETCH,
80         EXPP_CONSTR_ITERATIONS,
81         EXPP_CONSTR_BONE,
82         EXPP_CONSTR_CHAINLEN,
83         EXPP_CONSTR_POSWEIGHT,
84         EXPP_CONSTR_ROTWEIGHT,
85         EXPP_CONSTR_ROTATE,
86         EXPP_CONSTR_USETIP,
87
88         EXPP_CONSTR_ACTION,
89         EXPP_CONSTR_START,
90         EXPP_CONSTR_END,
91         EXPP_CONSTR_MIN,
92         EXPP_CONSTR_MAX,
93         EXPP_CONSTR_KEYON,
94
95         EXPP_CONSTR_TRACK,
96         EXPP_CONSTR_UP,
97
98         EXPP_CONSTR_RESTLENGTH,
99         EXPP_CONSTR_VOLVARIATION,
100         EXPP_CONSTR_VOLUMEMODE,
101         EXPP_CONSTR_PLANE,
102
103         EXPP_CONSTR_FOLLOW,
104         EXPP_CONSTR_OFFSET,
105         EXPP_CONSTR_FORWARD,
106
107         EXPP_CONSTR_LOCK,
108
109         EXPP_CONSTR_MINMAX,
110         EXPP_CONSTR_STICKY,
111
112         EXPP_CONSTR_COPY,
113         EXPP_CONSTR_LIMIT,
114         EXPP_CONSTR_CLAMP,
115         
116         EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
117         EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
118         EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
119         EXPP_CONSTR_LIMYMAX = LIMIT_YMAX,
120         EXPP_CONSTR_LIMZMIN = LIMIT_ZMIN,
121         EXPP_CONSTR_LIMZMAX = LIMIT_ZMAX,
122         
123         EXPP_CONSTR_LIMXROT = LIMIT_XROT,
124         EXPP_CONSTR_LIMYROT = LIMIT_YROT,
125         EXPP_CONSTR_LIMZROT = LIMIT_ZROT,
126         
127         EXPP_CONSTR_XMIN,
128         EXPP_CONSTR_XMAX,
129         EXPP_CONSTR_YMIN,
130         EXPP_CONSTR_YMAX,
131         EXPP_CONSTR_ZMIN,
132         EXPP_CONSTR_ZMAX,
133         
134         EXPP_CONSTR_SCRIPT,
135         EXPP_CONSTR_PROPS,
136         
137         EXPP_CONSTR_FROM,
138         EXPP_CONSTR_TO,
139         EXPP_CONSTR_EXPO,
140         EXPP_CONSTR_FROMMINX,
141         EXPP_CONSTR_FROMMAXX,
142         EXPP_CONSTR_FROMMINY,
143         EXPP_CONSTR_FROMMAXY,
144         EXPP_CONSTR_FROMMINZ,
145         EXPP_CONSTR_FROMMAXZ,
146         EXPP_CONSTR_TOMINX,
147         EXPP_CONSTR_TOMAXX,
148         EXPP_CONSTR_TOMINY,
149         EXPP_CONSTR_TOMAXY,
150         EXPP_CONSTR_TOMINZ,
151         EXPP_CONSTR_TOMAXZ,
152         EXPP_CONSTR_MAPX,
153         EXPP_CONSTR_MAPY,
154         EXPP_CONSTR_MAPZ,
155         
156         EXPP_CONSTR_OWNSPACE,
157         EXPP_CONSTR_TARSPACE,
158                 
159         EXPP_CONSTR_RB_TYPE,
160         EXPP_CONSTR_RB_BALL,
161         EXPP_CONSTR_RB_HINGE,
162         EXPP_CONSTR_RB_GENERIC6DOF,
163         EXPP_CONSTR_RB_VEHICLE,
164         EXPP_CONSTR_RB_PIVX,
165         EXPP_CONSTR_RB_PIVY,
166         EXPP_CONSTR_RB_PIVZ,
167         EXPP_CONSTR_RB_AXX,
168         EXPP_CONSTR_RB_AXY,
169         EXPP_CONSTR_RB_AXZ,
170         EXPP_CONSTR_RB_MINLIMIT0,
171         EXPP_CONSTR_RB_MINLIMIT1,
172         EXPP_CONSTR_RB_MINLIMIT2,
173         EXPP_CONSTR_RB_MINLIMIT3,
174         EXPP_CONSTR_RB_MINLIMIT4,
175         EXPP_CONSTR_RB_MINLIMIT5,
176         EXPP_CONSTR_RB_MAXLIMIT0,
177         EXPP_CONSTR_RB_MAXLIMIT1,
178         EXPP_CONSTR_RB_MAXLIMIT2,
179         EXPP_CONSTR_RB_MAXLIMIT3,
180         EXPP_CONSTR_RB_MAXLIMIT4,
181         EXPP_CONSTR_RB_MAXLIMIT5,
182         EXPP_CONSTR_RB_EXTRAFZ,
183         EXPP_CONSTR_RB_FLAG,
184         
185 };
186
187 /*****************************************************************************/
188 /* Python BPy_Constraint methods declarations:                               */
189 /*****************************************************************************/
190 static PyObject *Constraint_getName( BPy_Constraint * self );
191 static int Constraint_setName( BPy_Constraint * self, PyObject *arg );
192 static PyObject *Constraint_getType( BPy_Constraint * self );
193 static PyObject *Constraint_getInfluence( BPy_Constraint * self );
194 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
195
196 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
197
198 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
199 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
200                 PyObject * value );
201
202 /*****************************************************************************/
203 /* Python BPy_Constraint methods table:                                      */
204 /*****************************************************************************/
205 static PyMethodDef BPy_Constraint_methods[] = {
206         /* name, method, flags, doc */
207         {"insertKey", ( PyCFunction ) Constraint_insertKey, METH_O,
208          "Insert influence keyframe for constraint"},
209         {NULL, NULL, 0, NULL}
210 };
211
212 /*****************************************************************************/
213 /* Python BPy_Constraint attributes get/set structure:                       */
214 /*****************************************************************************/
215 static PyGetSetDef BPy_Constraint_getseters[] = {
216         {"name",
217         (getter)Constraint_getName, (setter)Constraint_setName,
218          "Constraint name", NULL},
219         {"type",
220         (getter)Constraint_getType, (setter)NULL,
221          "Constraint type (read only)", NULL},
222         {"influence",
223         (getter)Constraint_getInfluence, (setter)Constraint_setInfluence,
224          "Constraint influence", NULL},
225         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
226 };
227
228 /*****************************************************************************/
229 /* Python Constraint_Type Mapping Methods table:                             */
230 /*****************************************************************************/
231 static PyMappingMethods Constraint_as_mapping = {
232         NULL,                               /* mp_length        */
233         ( binaryfunc ) Constraint_getData,      /* mp_subscript     */
234         ( objobjargproc ) Constraint_setData,   /* mp_ass_subscript */
235 };
236
237 /*****************************************************************************/
238 /* Python Constraint_Type callback function prototypes:                      */
239 /*****************************************************************************/
240 static PyObject *Constraint_repr( BPy_Constraint * self );
241 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
242
243 /*****************************************************************************/
244 /* Python Constraint_Type structure definition:                              */
245 /*****************************************************************************/
246 PyTypeObject Constraint_Type = {
247         PyObject_HEAD_INIT( NULL )  /* required py macro */
248         0,                          /* ob_size */
249         /*  For printing, in format "<module>.<name>" */
250         "Blender Constraint",         /* char *tp_name; */
251         sizeof( BPy_Constraint ),     /* int tp_basicsize; */
252         0,                          /* tp_itemsize;  For allocation */
253
254         /* Methods to implement standard operations */
255
256         NULL,                                           /* destructor tp_dealloc; */
257         NULL,                       /* printfunc tp_print; */
258         NULL,                       /* getattrfunc tp_getattr; */
259         NULL,                       /* setattrfunc tp_setattr; */
260         ( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
261         ( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
262
263         /* Method suites for standard classes */
264
265         NULL,                       /* PyNumberMethods *tp_as_number; */
266         NULL,                       /* PySequenceMethods *tp_as_sequence; */
267         &Constraint_as_mapping,       /* PyMappingMethods *tp_as_mapping; */
268
269         /* More standard operations (here for binary compatibility) */
270
271         NULL,                       /* hashfunc tp_hash; */
272         NULL,                       /* ternaryfunc tp_call; */
273         NULL,                       /* reprfunc tp_str; */
274         NULL,                       /* getattrofunc tp_getattro; */
275         NULL,                       /* setattrofunc tp_setattro; */
276
277         /* Functions to access object as input/output buffer */
278         NULL,                       /* PyBufferProcs *tp_as_buffer; */
279
280   /*** Flags to define presence of optional/expanded features ***/
281         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
282
283         NULL,                       /*  char *tp_doc;  Documentation string */
284   /*** Assigned meaning in release 2.0 ***/
285         /* call function for all accessible objects */
286         NULL,                       /* traverseproc tp_traverse; */
287
288         /* delete references to contained objects */
289         NULL,                       /* inquiry tp_clear; */
290
291   /***  Assigned meaning in release 2.1 ***/
292   /*** rich comparisons ***/
293         NULL,                       /* richcmpfunc tp_richcompare; */
294
295   /***  weak reference enabler ***/
296         0,                          /* long tp_weaklistoffset; */
297
298   /*** Added in release 2.2 ***/
299         /*   Iterators */
300         NULL,                       /* getiterfunc tp_iter; */
301         NULL,                       /* iternextfunc tp_iternext; */
302
303   /*** Attribute descriptor and subclassing stuff ***/
304         BPy_Constraint_methods,       /* struct PyMethodDef *tp_methods; */
305         NULL,                       /* struct PyMemberDef *tp_members; */
306         BPy_Constraint_getseters,     /* struct PyGetSetDef *tp_getset; */
307         NULL,                       /* struct _typeobject *tp_base; */
308         NULL,                       /* PyObject *tp_dict; */
309         NULL,                       /* descrgetfunc tp_descr_get; */
310         NULL,                       /* descrsetfunc tp_descr_set; */
311         0,                          /* long tp_dictoffset; */
312         NULL,                       /* initproc tp_init; */
313         NULL,                       /* allocfunc tp_alloc; */
314         NULL,                       /* newfunc tp_new; */
315         /*  Low-level free-memory routine */
316         NULL,                       /* freefunc tp_free;  */
317         /* For PyObject_IS_GC */
318         NULL,                       /* inquiry tp_is_gc;  */
319         NULL,                       /* PyObject *tp_bases; */
320         /* method resolution order */
321         NULL,                       /* PyObject *tp_mro;  */
322         NULL,                       /* PyObject *tp_cache; */
323         NULL,                       /* PyObject *tp_subclasses; */
324         NULL,                       /* PyObject *tp_weaklist; */
325         NULL
326 };
327
328 /*****************************************************************************/
329 /* Python BPy_Constraint methods:                                            */
330 /*****************************************************************************/
331
332 /*
333  * return the name of this constraint
334  */
335
336 static PyObject *Constraint_getName( BPy_Constraint * self )
337 {
338         if( !self->con )
339                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
340                                 "This constraint has been removed!" );
341         
342         return PyString_FromString( self->con->name );
343 }
344
345 /*
346  * set the name of this constraint
347  */
348
349 static int Constraint_setName( BPy_Constraint * self, PyObject * attr )
350 {
351         char *name = PyString_AsString( attr );
352         if( !name )
353                 return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
354
355         if( !self->con )
356                 return EXPP_ReturnIntError( PyExc_RuntimeError,
357                                 "This constraint has been removed!" );
358         
359         BLI_strncpy( self->con->name, name, sizeof( self->con->name ) );
360
361         return 0;
362 }
363
364 /*
365  * return the influence of this constraint
366  */
367
368 static PyObject *Constraint_getInfluence( BPy_Constraint * self )
369 {
370         if( !self->con )
371                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
372                                 "This constraint has been removed!" );
373         
374         return PyFloat_FromDouble( (double)self->con->enforce );
375 }
376
377 /*
378  * set the influence of this constraint
379  */
380
381 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * value )
382 {
383         if( !self->con )
384                 return EXPP_ReturnIntError( PyExc_RuntimeError,
385                                 "This constraint has been removed!" );
386
387         return EXPP_setFloatClamped( value, &self->con->enforce, 0.0, 1.0 );
388 }
389
390 /*
391  * return the type of this constraint
392  */
393
394 static PyObject *Constraint_getType( BPy_Constraint * self )
395 {
396         if( !self->con )
397                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
398                                 "This constraint has been removed!" );
399         
400         return PyInt_FromLong( self->con->type );
401 }
402
403 /*
404  * add keyframe for influence
405         base on code in add_influence_key_to_constraint_func()
406  */
407 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * value )
408 {
409         IpoCurve *icu;
410         float cfra = (float)PyFloat_AsDouble(value);
411         char actname[32] = "";
412         Object *ob = self->obj;
413         bConstraint *con = self->con;
414
415         if( !self->con )
416                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
417                                 "This constraint has been removed!" );
418
419         /* get frame for inserting key */
420         if( PyFloat_Check(value) )
421                 return EXPP_ReturnPyObjError( PyExc_TypeError,
422                                 "expected a float argument" );
423
424         /* constraint_active_func(ob_v, con_v); */
425         get_constraint_ipo_context( ob, actname );
426         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
427         
428         if (!icu)
429                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
430                                 "cannot get a curve from this IPO, may be using libdata" );
431         
432         if( ob->action )
433                 insert_vert_ipo( icu, get_action_frame(ob, cfra), con->enforce);
434         else
435                 insert_vert_ipo( icu, cfra, con->enforce);
436
437         Py_RETURN_NONE;
438 }
439
440 /*****************************************************************************/
441 /* Specific constraint get/set procedures                                    */
442 /*****************************************************************************/
443
444 static PyObject *kinematic_getter( BPy_Constraint * self, int type )
445 {
446         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
447
448         switch( type ) {
449         case EXPP_CONSTR_TARGET:
450                 return Object_CreatePyObject( con->tar );
451         case EXPP_CONSTR_BONE:
452                 return PyString_FromString( con->subtarget );
453         case EXPP_CONSTR_STRETCH:
454                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_STRETCH ) ) ;
455         case EXPP_CONSTR_ITERATIONS:
456                 return PyInt_FromLong( (long)con->iterations );
457         case EXPP_CONSTR_CHAINLEN:
458                 return PyInt_FromLong( (long)con->rootbone );
459         case EXPP_CONSTR_POSWEIGHT:
460                 return PyFloat_FromDouble( (double)con->weight );
461         case EXPP_CONSTR_ROTWEIGHT:
462                 return PyFloat_FromDouble( (double)con->orientweight );
463         case EXPP_CONSTR_ROTATE:
464                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_ROT ) ) ;
465         case EXPP_CONSTR_USETIP:
466                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_TIP ) ) ;
467         default:
468                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
469         }
470 }
471
472 static int kinematic_setter( BPy_Constraint *self, int type, PyObject *value )
473 {
474         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
475
476         switch( type ) {
477         case EXPP_CONSTR_TARGET: {
478                 Object *obj = (( BPy_Object * )value)->object;
479                 if( !BPy_Object_Check( value ) )
480                         return EXPP_ReturnIntError( PyExc_TypeError, 
481                                         "expected BPy object argument" );
482                 con->tar = obj;
483                 return 0;
484                 }
485         case EXPP_CONSTR_BONE: {
486                 char *name = PyString_AsString( value );
487                 if( !name )
488                         return EXPP_ReturnIntError( PyExc_TypeError,
489                                         "expected string arg" );
490
491                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
492
493                 return 0;
494                 }
495         case EXPP_CONSTR_STRETCH:
496                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_STRETCH, 'h' );
497         case EXPP_CONSTR_ITERATIONS:
498                 return EXPP_setIValueClamped( value, &con->iterations, 1, 10000, 'h' );
499         case EXPP_CONSTR_CHAINLEN:
500                 return EXPP_setIValueClamped( value, &con->rootbone, 0, 255, 'i' );
501         case EXPP_CONSTR_POSWEIGHT:
502                 return EXPP_setFloatClamped( value, &con->weight, 0.01f, 1.0 );
503         case EXPP_CONSTR_ROTWEIGHT:
504                 return EXPP_setFloatClamped( value, &con->orientweight, 0.01f, 1.0 );
505         case EXPP_CONSTR_ROTATE:
506                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_ROT, 'h' );
507         case EXPP_CONSTR_USETIP:
508                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_TIP, 'h' );
509         default:
510                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
511         }
512 }
513
514 static PyObject *action_getter( BPy_Constraint * self, int type )
515 {
516         bActionConstraint *con = (bActionConstraint *)(self->con->data);
517
518         switch( type ) {
519         case EXPP_CONSTR_TARGET:
520                 return Object_CreatePyObject( con->tar );
521         case EXPP_CONSTR_BONE:
522                 return PyString_FromString( con->subtarget );
523         case EXPP_CONSTR_ACTION:
524                 return Action_CreatePyObject( con->act );
525         case EXPP_CONSTR_START:
526                 return PyInt_FromLong( (long)con->start );
527         case EXPP_CONSTR_END:
528                 return PyInt_FromLong( (long)con->end );
529         case EXPP_CONSTR_MIN:
530                 return PyFloat_FromDouble( (double)con->min );
531         case EXPP_CONSTR_MAX:
532                 return PyFloat_FromDouble( (double)con->max );
533         case EXPP_CONSTR_KEYON:
534                 return PyInt_FromLong( (long)con->type );
535         default:
536                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
537         }
538 }
539
540 static int action_setter( BPy_Constraint *self, int type, PyObject *value )
541 {
542         bActionConstraint *con = (bActionConstraint *)(self->con->data);
543
544         switch( type ) {
545         case EXPP_CONSTR_TARGET: {
546                 Object *obj = (( BPy_Object * )value)->object;
547                 if( !BPy_Object_Check( value ) )
548                         return EXPP_ReturnIntError( PyExc_TypeError, 
549                                         "expected BPy object argument" );
550                 con->tar = obj;
551                 return 0;
552                 }
553         case EXPP_CONSTR_BONE: {
554                 char *name = PyString_AsString( value );
555                 if( !name )
556                         return EXPP_ReturnIntError( PyExc_TypeError,
557                                         "expected string arg" );
558
559                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
560
561                 return 0;
562                 }
563         case EXPP_CONSTR_ACTION: {
564                 bAction *act = (( BPy_Action * )value)->action;
565                 if( !BPy_Action_Check( value ) )
566                         return EXPP_ReturnIntError( PyExc_TypeError, 
567                                         "expected BPy action argument" );
568                 con->act = act;
569                 return 0;
570                 }
571         case EXPP_CONSTR_START:
572                 return EXPP_setIValueClamped( value, &con->start, 1, MAXFRAME, 'h' );
573         case EXPP_CONSTR_END:
574                 return EXPP_setIValueClamped( value, &con->end, 1, MAXFRAME, 'h' );
575         case EXPP_CONSTR_MIN:
576                 if (con->type < 10)
577                         return EXPP_setFloatClamped( value, &con->min, -180.0, 180.0 );
578                 else if (con->type < 20)
579                         return EXPP_setFloatClamped( value, &con->min, 0.0001, 1000.0 );
580                 else 
581                         return EXPP_setFloatClamped( value, &con->min, -1000.0, 1000.0 );
582         case EXPP_CONSTR_MAX:
583                 if (con->type < 10)
584                         return EXPP_setFloatClamped( value, &con->max, -180.0, 180.0 );
585                 else if (con->type < 20)
586                         return EXPP_setFloatClamped( value, &con->max, 0.0001, 1000.0 );
587                 else 
588                         return EXPP_setFloatClamped( value, &con->max, -1000.0, 1000.0 );
589         case EXPP_CONSTR_KEYON:
590                 return EXPP_setIValueRange( value, &con->type,
591                                 EXPP_CONSTR_XROT, EXPP_CONSTR_ZLOC, 'h' );
592         default:
593                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
594         }
595 }
596
597 static PyObject *trackto_getter( BPy_Constraint * self, int type )
598 {
599         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
600
601         switch( type ) {
602         case EXPP_CONSTR_TARGET:
603                 return Object_CreatePyObject( con->tar );
604         case EXPP_CONSTR_BONE:
605                 return PyString_FromString( con->subtarget );
606         case EXPP_CONSTR_TRACK:
607                 return PyInt_FromLong( (long)con->reserved1 );
608         case EXPP_CONSTR_UP:
609                 return PyInt_FromLong( (long)con->reserved2 );
610         default:
611                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
612         }
613 }
614
615 static int trackto_setter( BPy_Constraint *self, int type, PyObject *value )
616 {
617         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
618
619         switch( type ) {
620         case EXPP_CONSTR_TARGET: {
621                 Object *obj = (( BPy_Object * )value)->object;
622                 if( !BPy_Object_Check( value ) )
623                         return EXPP_ReturnIntError( PyExc_TypeError, 
624                                         "expected BPy object argument" );
625                 con->tar = obj;
626                 return 0;
627                 }
628         case EXPP_CONSTR_BONE: {
629                 char *name = PyString_AsString( value );
630                 if( !name )
631                         return EXPP_ReturnIntError( PyExc_TypeError,
632                                         "expected string arg" );
633
634                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
635
636                 return 0;
637                 }
638         case EXPP_CONSTR_TRACK:
639                 return EXPP_setIValueRange( value, &con->reserved1,
640                                 TRACK_X, TRACK_nZ, 'i' );
641         case EXPP_CONSTR_UP:
642                 return EXPP_setIValueRange( value, &con->reserved2,
643                                 UP_X, UP_Z, 'i' );
644         default:
645                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
646         }
647 }
648
649 static PyObject *stretchto_getter( BPy_Constraint * self, int type )
650 {
651         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
652
653         switch( type ) {
654         case EXPP_CONSTR_TARGET:
655                 return Object_CreatePyObject( con->tar );
656         case EXPP_CONSTR_BONE:
657                 return PyString_FromString( con->subtarget );
658         case EXPP_CONSTR_RESTLENGTH:
659                 return PyFloat_FromDouble( (double)con->orglength );
660         case EXPP_CONSTR_VOLVARIATION:
661                 return PyFloat_FromDouble( (double)con->bulge );
662         case EXPP_CONSTR_VOLUMEMODE:
663                 return PyInt_FromLong( (long)con->volmode );
664         case EXPP_CONSTR_PLANE:
665                 return PyInt_FromLong( (long)con->plane );
666         default:
667                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
668         }
669 }
670
671 static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
672 {
673         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
674
675         switch( type ) {
676         case EXPP_CONSTR_TARGET: {
677                 Object *obj = (( BPy_Object * )value)->object;
678                 if( !BPy_Object_Check( value ) )
679                         return EXPP_ReturnIntError( PyExc_TypeError, 
680                                         "expected BPy object argument" );
681                 con->tar = obj;
682                 return 0;
683                 }
684         case EXPP_CONSTR_BONE: {
685                 char *name = PyString_AsString( value );
686                 if( !name )
687                         return EXPP_ReturnIntError( PyExc_TypeError,
688                                         "expected string arg" );
689
690                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
691
692                 return 0;
693                 }
694         case EXPP_CONSTR_RESTLENGTH:
695                 return EXPP_setFloatClamped( value, &con->orglength, 0.0, 100.0 );
696         case EXPP_CONSTR_VOLVARIATION:
697                 return EXPP_setFloatClamped( value, &con->bulge, 0.0, 100.0 );
698         case EXPP_CONSTR_VOLUMEMODE:
699                 return EXPP_setIValueRange( value, &con->volmode,
700                                 VOLUME_XZ, NO_VOLUME, 'h' );
701         case EXPP_CONSTR_PLANE: {
702                 int status, oldcode = con->plane;
703                 status = EXPP_setIValueRange( value, &con->plane,
704                                 PLANE_X, PLANE_Z, 'h' );
705                 if( !status && con->plane == PLANE_Y ) {
706                         con->plane = oldcode;
707                         return EXPP_ReturnIntError( PyExc_ValueError,
708                                         "value must be either PLANEX or PLANEZ" );
709                 }
710                 return status;
711                 }
712         default:
713                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
714         }
715 }
716
717 static PyObject *followpath_getter( BPy_Constraint * self, int type )
718 {
719         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
720
721         switch( type ) {
722         case EXPP_CONSTR_TARGET:
723                 return Object_CreatePyObject( con->tar );
724         case EXPP_CONSTR_FOLLOW:
725                 return PyBool_FromLong( (long)( con->followflag & SELECT ) );
726         case EXPP_CONSTR_OFFSET:
727                 return PyFloat_FromDouble( (double)con->offset );
728         case EXPP_CONSTR_FORWARD:
729                 return PyInt_FromLong( (long)con->trackflag );
730         case EXPP_CONSTR_UP:
731                 return PyInt_FromLong( (long)con->upflag );
732         default:
733                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
734         }
735 }
736
737 static int followpath_setter( BPy_Constraint *self, int type, PyObject *value )
738 {
739         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
740
741         switch( type ) {
742         case EXPP_CONSTR_TARGET: {
743                 Object *obj = (( BPy_Object * )value)->object;
744                 if( !BPy_Object_Check( value ) )
745                         return EXPP_ReturnIntError( PyExc_TypeError, 
746                                         "expected BPy object argument" );
747                 con->tar = obj;
748                 return 0;
749                 }
750         case EXPP_CONSTR_FOLLOW:
751                 return EXPP_setBitfield( value, &con->followflag, SELECT, 'i' );
752         case EXPP_CONSTR_OFFSET:
753                 return EXPP_setFloatClamped( value, &con->offset,
754                                 -MAXFRAMEF, MAXFRAMEF );
755         case EXPP_CONSTR_FORWARD:
756                 return EXPP_setIValueRange( value, &con->trackflag,
757                                 TRACK_X, TRACK_nZ, 'i' );
758         case EXPP_CONSTR_UP:
759                 return EXPP_setIValueRange( value, &con->upflag,
760                                 UP_X, UP_Z, 'i' );
761         default:
762                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
763         }
764 }
765
766 static PyObject *clampto_getter( BPy_Constraint * self, int type )
767 {
768         bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
769
770         switch( type ) {
771         case EXPP_CONSTR_TARGET:
772                 return Object_CreatePyObject( con->tar );
773         case EXPP_CONSTR_CLAMP:
774                 return PyInt_FromLong( (long)con->flag );
775         default:
776                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
777         }
778 }
779
780 static int clampto_setter( BPy_Constraint *self, int type, PyObject *value )
781 {
782         bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
783
784         switch( type ) {
785         case EXPP_CONSTR_TARGET: {
786                 Object *obj = (( BPy_Object * )value)->object;
787                 if( !BPy_Object_Check( value ) )
788                         return EXPP_ReturnIntError( PyExc_TypeError, 
789                                         "expected BPy object argument" );
790                 con->tar = obj;
791                 return 0;
792                 }
793         case EXPP_CONSTR_CLAMP:
794                 return EXPP_setIValueRange( value, &con->flag,
795                                 CLAMPTO_AUTO, CLAMPTO_Z, 'i' );
796         default:
797                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
798         }
799 }
800 static PyObject *locktrack_getter( BPy_Constraint * self, int type )
801 {
802         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
803
804         switch( type ) {
805         case EXPP_CONSTR_TARGET:
806                 return Object_CreatePyObject( con->tar );
807         case EXPP_CONSTR_BONE:
808                 return PyString_FromString( con->subtarget );
809         case EXPP_CONSTR_TRACK:
810                 return PyInt_FromLong( (long)con->trackflag );
811         case EXPP_CONSTR_LOCK:
812                 return PyInt_FromLong( (long)con->lockflag );
813         default:
814                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
815         }
816 }
817
818 static int locktrack_setter( BPy_Constraint *self, int type, PyObject *value )
819 {
820         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
821
822         switch( type ) {
823         case EXPP_CONSTR_TARGET: {
824                 Object *obj = (( BPy_Object * )value)->object;
825                 if( !BPy_Object_Check( value ) )
826                         return EXPP_ReturnIntError( PyExc_TypeError, 
827                                         "expected BPy object argument" );
828                 con->tar = obj;
829                 return 0;
830                 }
831         case EXPP_CONSTR_BONE: {
832                 char *name = PyString_AsString( value );
833                 if( !name )
834                         return EXPP_ReturnIntError( PyExc_TypeError,
835                                         "expected string arg" );
836
837                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
838
839                 return 0;
840                 }
841         case EXPP_CONSTR_TRACK:
842                 return EXPP_setIValueRange( value, &con->trackflag,
843                                 TRACK_X, TRACK_nZ, 'i' );
844         case EXPP_CONSTR_LOCK:
845                 return EXPP_setIValueRange( value, &con->lockflag,
846                                 LOCK_X, LOCK_Z, 'i' );
847         default:
848                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
849         }
850 }
851
852 static PyObject *floor_getter( BPy_Constraint * self, int type )
853 {
854         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
855
856         switch( type ) {
857         case EXPP_CONSTR_TARGET:
858                 return Object_CreatePyObject( con->tar );
859         case EXPP_CONSTR_BONE:
860                 return PyString_FromString( con->subtarget );
861         case EXPP_CONSTR_MINMAX:
862                 return PyInt_FromLong( (long)con->minmaxflag );
863         case EXPP_CONSTR_OFFSET:
864                 return PyFloat_FromDouble( (double)con->offset );
865         case EXPP_CONSTR_STICKY:
866                 return PyBool_FromLong( (long)( con->flag & MINMAX_STICKY ) ) ;
867         default:
868                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
869         }
870 }
871
872 static int floor_setter( BPy_Constraint *self, int type, PyObject *value )
873 {
874         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
875
876         switch( type ) {
877         case EXPP_CONSTR_TARGET: {
878                 Object *obj = (( BPy_Object * )value)->object;
879                 if( !BPy_Object_Check( value ) )
880                         return EXPP_ReturnIntError( PyExc_TypeError, 
881                                         "expected BPy object argument" );
882                 con->tar = obj;
883                 return 0;
884                 }
885         case EXPP_CONSTR_BONE: {
886                 char *name = PyString_AsString( value );
887                 if( !name )
888                         return EXPP_ReturnIntError( PyExc_TypeError,
889                                         "expected string arg" );
890
891                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
892
893                 return 0;
894                 }
895         case EXPP_CONSTR_MINMAX:
896                 return EXPP_setIValueRange( value, &con->minmaxflag,
897                                 EXPP_CONSTR_MAXX, EXPP_CONSTR_MINZ, 'i' );
898         case EXPP_CONSTR_OFFSET:
899                 return EXPP_setFloatClamped( value, &con->offset, -100.0, 100.0 );
900         case EXPP_CONSTR_STICKY:
901                 return EXPP_setBitfield( value, &con->flag, MINMAX_STICKY, 'h' );
902         default:
903                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
904         }
905 }
906
907 static PyObject *locatelike_getter( BPy_Constraint * self, int type )
908 {
909         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
910
911         switch( type ) {
912         case EXPP_CONSTR_TARGET:
913                 return Object_CreatePyObject( con->tar );
914         case EXPP_CONSTR_BONE:
915                 return PyString_FromString( con->subtarget );
916         case EXPP_CONSTR_COPY:
917                 return PyInt_FromLong( (long)con->flag );
918         default:
919                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
920         }
921 }
922
923 static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
924 {
925         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
926
927         switch( type ) {
928         case EXPP_CONSTR_TARGET: {
929                 Object *obj = (( BPy_Object * )value)->object;
930                 if( !BPy_Object_Check( value ) )
931                         return EXPP_ReturnIntError( PyExc_TypeError, 
932                                         "expected BPy object argument" );
933                 con->tar = obj;
934                 return 0;
935                 }
936         case EXPP_CONSTR_BONE: {
937                 char *name = PyString_AsString( value );
938                 if( !name )
939                         return EXPP_ReturnIntError( PyExc_TypeError,
940                                         "expected string arg" );
941
942                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
943
944                 return 0;
945                 }
946         case EXPP_CONSTR_COPY:
947                 return EXPP_setIValueRange( value, &con->flag,
948                                 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z | LOCLIKE_X_INVERT | LOCLIKE_Y_INVERT | LOCLIKE_Z_INVERT, 'i' );
949         default:
950                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
951         }
952 }
953
954 static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
955 {
956         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
957
958         switch( type ) {
959         case EXPP_CONSTR_TARGET:
960                 return Object_CreatePyObject( con->tar );
961         case EXPP_CONSTR_BONE:
962                 return PyString_FromString( con->subtarget );
963         case EXPP_CONSTR_COPY:
964                 return PyInt_FromLong( (long)con->flag );
965         default:
966                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
967         }
968 }
969
970 static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
971 {
972         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
973
974         switch( type ) {
975         case EXPP_CONSTR_TARGET: {
976                 Object *obj = (( BPy_Object * )value)->object;
977                 if( !BPy_Object_Check( value ) )
978                         return EXPP_ReturnIntError( PyExc_TypeError, 
979                                         "expected BPy object argument" );
980                 con->tar = obj;
981                 return 0;
982                 }
983         case EXPP_CONSTR_BONE: {
984                 char *name = PyString_AsString( value );
985                 if( !name )
986                         return EXPP_ReturnIntError( PyExc_TypeError,
987                                         "expected string arg" );
988
989                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
990
991                 return 0;
992                 }
993         case EXPP_CONSTR_COPY:
994                 return EXPP_setIValueRange( value, &con->flag,
995                                 0, ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z | ROTLIKE_X_INVERT | ROTLIKE_Y_INVERT | ROTLIKE_Z_INVERT, 'i' );
996         default:
997                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
998         }
999 }
1000
1001 static PyObject *sizelike_getter( BPy_Constraint * self, int type )
1002 {
1003         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1004
1005         switch( type ) {
1006         case EXPP_CONSTR_TARGET:
1007                 return Object_CreatePyObject( con->tar );
1008         case EXPP_CONSTR_BONE:
1009                 return PyString_FromString( con->subtarget );
1010         case EXPP_CONSTR_COPY:
1011                 return PyInt_FromLong( (long)con->flag );
1012         default:
1013                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1014         }
1015 }
1016
1017 static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
1018 {
1019         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1020
1021         switch( type ) {
1022         case EXPP_CONSTR_TARGET: {
1023                 Object *obj = (( BPy_Object * )value)->object;
1024                 if( !BPy_Object_Check( value ) )
1025                         return EXPP_ReturnIntError( PyExc_TypeError, 
1026                                         "expected BPy object argument" );
1027                 con->tar = obj;
1028                 return 0;
1029                 }
1030         case EXPP_CONSTR_BONE: {
1031                 char *name = PyString_AsString( value );
1032                 if( !name )
1033                         return EXPP_ReturnIntError( PyExc_TypeError,
1034                                         "expected string arg" );
1035
1036                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1037
1038                 return 0;
1039                 }
1040         case EXPP_CONSTR_COPY:
1041                 return EXPP_setIValueRange( value, &con->flag,
1042                                 0, SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z, 'i' );
1043         default:
1044                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1045         }
1046 }
1047
1048 static PyObject *loclimit_getter( BPy_Constraint * self, int type)
1049 {
1050         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1051
1052         switch( type ) {
1053         case EXPP_CONSTR_LIMIT:
1054                 return PyInt_FromLong( (long)con->flag );
1055         case EXPP_CONSTR_XMIN:
1056                 return PyFloat_FromDouble( (double)con->xmin );
1057         case EXPP_CONSTR_XMAX:
1058                 return PyFloat_FromDouble( (double)con->xmax );
1059         case EXPP_CONSTR_YMIN:
1060                 return PyFloat_FromDouble( (double)con->ymin );
1061         case EXPP_CONSTR_YMAX:
1062                 return PyFloat_FromDouble( (double)con->ymax );
1063         case EXPP_CONSTR_ZMIN:
1064                 return PyFloat_FromDouble( (double)con->zmin );
1065         case EXPP_CONSTR_ZMAX:
1066                 return PyFloat_FromDouble( (double)con->zmax );
1067         default:
1068                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1069         }
1070 }
1071
1072 static int loclimit_setter( BPy_Constraint *self, int type, PyObject *value )
1073 {
1074         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);    
1075         
1076         switch( type ) {
1077         case EXPP_CONSTR_LIMIT:
1078                 return EXPP_setIValueRange( value, &con->flag, 0, 
1079                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX , 'i' );
1080         case EXPP_CONSTR_XMIN:
1081                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1082         case EXPP_CONSTR_XMAX:
1083                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1084         case EXPP_CONSTR_YMIN:
1085                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1086         case EXPP_CONSTR_YMAX:
1087                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1088         case EXPP_CONSTR_ZMIN:
1089                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1090         case EXPP_CONSTR_ZMAX:
1091                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1092         default:
1093                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1094         }
1095 }
1096
1097 static PyObject *rotlimit_getter( BPy_Constraint * self, int type )
1098 {
1099         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1100
1101         switch( type ) {
1102         case EXPP_CONSTR_LIMIT:
1103                 return PyInt_FromLong( (long)con->flag );
1104         case EXPP_CONSTR_XMIN:
1105                 return PyFloat_FromDouble( (double)con->xmin );
1106         case EXPP_CONSTR_XMAX:
1107                 return PyFloat_FromDouble( (double)con->xmax );
1108         case EXPP_CONSTR_YMIN:
1109                 return PyFloat_FromDouble( (double)con->ymin );
1110         case EXPP_CONSTR_YMAX:
1111                 return PyFloat_FromDouble( (double)con->ymax );
1112         case EXPP_CONSTR_ZMIN:
1113                 return PyFloat_FromDouble( (double)con->zmin );
1114         case EXPP_CONSTR_ZMAX:
1115                 return PyFloat_FromDouble( (double)con->zmax );
1116         default:
1117                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1118         }
1119 }
1120
1121 static int rotlimit_setter( BPy_Constraint *self, int type, PyObject *value )
1122 {
1123         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);    
1124         
1125         switch( type ) {
1126         case EXPP_CONSTR_LIMIT:
1127                 return EXPP_setIValueRange( value, &con->flag, 0, 
1128                         LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT, 'i' );
1129         case EXPP_CONSTR_XMIN:
1130                 return EXPP_setFloatClamped( value, &con->xmin, -360.0, 360.0 );
1131         case EXPP_CONSTR_XMAX:
1132                 return EXPP_setFloatClamped( value, &con->xmax, -360.0, 360.0 );
1133         case EXPP_CONSTR_YMIN:
1134                 return EXPP_setFloatClamped( value, &con->ymin, -360.0, 360.0 );
1135         case EXPP_CONSTR_YMAX:
1136                 return EXPP_setFloatClamped( value, &con->ymax, -360.0, 360.0 );
1137         case EXPP_CONSTR_ZMIN:
1138                 return EXPP_setFloatClamped( value, &con->zmin, -360.0, 360.0 );
1139         case EXPP_CONSTR_ZMAX:
1140                 return EXPP_setFloatClamped( value, &con->zmax, -360.0, 360.0 );
1141         default:
1142                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1143         }
1144 }
1145
1146 static PyObject *sizelimit_getter( BPy_Constraint * self, int type)
1147 {
1148         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1149
1150         switch( type ) {
1151         case EXPP_CONSTR_LIMIT:
1152                 return PyInt_FromLong( (long)con->flag );
1153         case EXPP_CONSTR_XMIN:
1154                 return PyFloat_FromDouble( (double)con->xmin );
1155         case EXPP_CONSTR_XMAX:
1156                 return PyFloat_FromDouble( (double)con->xmax );
1157         case EXPP_CONSTR_YMIN:
1158                 return PyFloat_FromDouble( (double)con->ymin );
1159         case EXPP_CONSTR_YMAX:
1160                 return PyFloat_FromDouble( (double)con->ymax );
1161         case EXPP_CONSTR_ZMIN:
1162                 return PyFloat_FromDouble( (double)con->zmin );
1163         case EXPP_CONSTR_ZMAX:
1164                 return PyFloat_FromDouble( (double)con->zmax );
1165         default:
1166                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1167         }
1168 }
1169
1170 static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
1171 {
1172         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);  
1173         
1174         switch( type ) {
1175         case EXPP_CONSTR_LIMIT:
1176                 return EXPP_setIValueRange( value, &con->flag, 0, 
1177                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1178         case EXPP_CONSTR_XMIN:
1179                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1180         case EXPP_CONSTR_XMAX:
1181                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1182         case EXPP_CONSTR_YMIN:
1183                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1184         case EXPP_CONSTR_YMAX:
1185                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1186         case EXPP_CONSTR_ZMIN:
1187                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1188         case EXPP_CONSTR_ZMAX:
1189                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1190         default:
1191                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1192         }
1193 }
1194
1195 static PyObject *script_getter( BPy_Constraint * self, int type )
1196 {
1197         bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1198
1199         switch( type ) {
1200         case EXPP_CONSTR_TARGET:
1201                 return Object_CreatePyObject( con->tar );
1202         case EXPP_CONSTR_BONE:
1203                 return PyString_FromString( con->subtarget );
1204         case EXPP_CONSTR_SCRIPT:
1205                 return Text_CreatePyObject( con->text );
1206         case EXPP_CONSTR_PROPS:
1207                 return BPy_Wrap_IDProperty( NULL, con->prop, NULL);
1208         default:
1209                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1210         }
1211 }
1212
1213 static int script_setter( BPy_Constraint *self, int type, PyObject *value )
1214 {
1215         bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1216
1217         switch( type ) {
1218         case EXPP_CONSTR_TARGET: {
1219                 Object *obj = (( BPy_Object * )value)->object;
1220                 if( !BPy_Object_Check( value ) )
1221                         return EXPP_ReturnIntError( PyExc_TypeError, 
1222                                         "expected BPy object argument" );
1223                 con->tar = obj;
1224                 return 0;
1225                 }
1226         case EXPP_CONSTR_BONE: {
1227                 char *name = PyString_AsString( value );
1228                 if( !name )
1229                         return EXPP_ReturnIntError( PyExc_TypeError,
1230                                         "expected string arg" );
1231
1232                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1233
1234                 return 0;
1235                 }
1236         case EXPP_CONSTR_SCRIPT: {
1237                 Text *text = (( BPy_Text * )value)->text;
1238                 if( !BPy_Object_Check( value ) )
1239                         return EXPP_ReturnIntError( PyExc_TypeError, 
1240                                         "expected BPy text argument" );
1241                 con->text = text;
1242                 return 0;
1243                 }
1244         case EXPP_CONSTR_PROPS:
1245                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1246                                         "setting ID-Properties of PyConstraints this way is not supported" );
1247         default:
1248                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1249         }
1250 }
1251
1252
1253 static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
1254 {
1255         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1256
1257         switch( type ) {
1258         case EXPP_CONSTR_TARGET:
1259                 return Object_CreatePyObject( con->tar );
1260         case EXPP_CONSTR_RB_PIVX:
1261                 return PyFloat_FromDouble( (double)con->pivX );
1262         case EXPP_CONSTR_RB_PIVY:
1263                 return PyFloat_FromDouble( (double)con->pivY );
1264         case EXPP_CONSTR_RB_PIVZ:
1265                 return PyFloat_FromDouble( (double)con->pivZ );
1266         case EXPP_CONSTR_RB_AXX:
1267                 return PyFloat_FromDouble( (double)con->axX );
1268         case EXPP_CONSTR_RB_AXY:
1269                 return PyFloat_FromDouble( (double)con->axY );
1270         case EXPP_CONSTR_RB_AXZ:
1271                 return PyFloat_FromDouble( (double)con->axZ );
1272         case EXPP_CONSTR_RB_MINLIMIT0:
1273                 return PyFloat_FromDouble( (double)con->minLimit[0] );
1274         case EXPP_CONSTR_RB_MINLIMIT1:
1275                 return PyFloat_FromDouble( (double)con->minLimit[1] );
1276         case EXPP_CONSTR_RB_MINLIMIT2:
1277                 return PyFloat_FromDouble( (double)con->minLimit[2] );
1278         case EXPP_CONSTR_RB_MINLIMIT3:
1279                 return PyFloat_FromDouble( (double)con->minLimit[3] );
1280         case EXPP_CONSTR_RB_MINLIMIT4:
1281                 return PyFloat_FromDouble( (double)con->minLimit[4] );
1282         case EXPP_CONSTR_RB_MINLIMIT5:
1283                 return PyFloat_FromDouble( (double)con->minLimit[5] );
1284         case EXPP_CONSTR_RB_MAXLIMIT0:
1285                 return PyFloat_FromDouble( (double)con->maxLimit[0] );
1286         case EXPP_CONSTR_RB_MAXLIMIT1:
1287                 return PyFloat_FromDouble( (double)con->maxLimit[1] );
1288         case EXPP_CONSTR_RB_MAXLIMIT2:
1289                 return PyFloat_FromDouble( (double)con->maxLimit[2] );
1290         case EXPP_CONSTR_RB_MAXLIMIT3:
1291                 return PyFloat_FromDouble( (double)con->maxLimit[3] );
1292         case EXPP_CONSTR_RB_MAXLIMIT4:
1293                 return PyFloat_FromDouble( (double)con->maxLimit[4] );
1294         case EXPP_CONSTR_RB_MAXLIMIT5:
1295                 return PyFloat_FromDouble( (double)con->maxLimit[5] );
1296         case EXPP_CONSTR_RB_EXTRAFZ:
1297                 return PyFloat_FromDouble( (double)con->extraFz );              
1298         case EXPP_CONSTR_LIMIT:
1299                 return PyInt_FromLong( (int)con->flag );
1300                 
1301         case EXPP_CONSTR_RB_TYPE:
1302                 return PyInt_FromLong( (int)con->type );
1303         default:
1304                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1305         }
1306 }
1307
1308
1309 static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
1310 {
1311         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);        
1312         
1313         switch( type ) {
1314         case EXPP_CONSTR_TARGET: {
1315                 Object *obj = (( BPy_Object * )value)->object;
1316                 if( !BPy_Object_Check( value ) )
1317                         return EXPP_ReturnIntError( PyExc_TypeError, 
1318                                         "expected BPy object argument" );
1319                 con->tar = obj;
1320                 return 0;
1321                 }
1322         case EXPP_CONSTR_RB_PIVX:
1323                 return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
1324         case EXPP_CONSTR_RB_PIVY:
1325                 return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
1326         case EXPP_CONSTR_RB_PIVZ:
1327                 return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
1328         case EXPP_CONSTR_RB_AXX:
1329                 return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
1330         case EXPP_CONSTR_RB_AXY:
1331                 return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
1332         case EXPP_CONSTR_RB_AXZ:
1333                 return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
1334         case EXPP_CONSTR_RB_MINLIMIT0:
1335                 return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
1336         case EXPP_CONSTR_RB_MINLIMIT1:
1337                 return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
1338         case EXPP_CONSTR_RB_MINLIMIT2:
1339                 return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
1340         case EXPP_CONSTR_RB_MINLIMIT3:
1341                 return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
1342         case EXPP_CONSTR_RB_MINLIMIT4:
1343                 return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
1344         case EXPP_CONSTR_RB_MINLIMIT5:
1345                 return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
1346         case EXPP_CONSTR_RB_MAXLIMIT0:
1347                 return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
1348         case EXPP_CONSTR_RB_MAXLIMIT1:
1349                 return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
1350         case EXPP_CONSTR_RB_MAXLIMIT2:
1351                 return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
1352         case EXPP_CONSTR_RB_MAXLIMIT3:
1353                 return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
1354         case EXPP_CONSTR_RB_MAXLIMIT4:
1355                 return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
1356         case EXPP_CONSTR_RB_MAXLIMIT5:
1357                 return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
1358         case EXPP_CONSTR_RB_EXTRAFZ:
1359                 return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );                                          
1360         case EXPP_CONSTR_LIMIT:
1361                 return EXPP_setIValueRange( value, &con->flag, 0, 
1362                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1363         case EXPP_CONSTR_RB_TYPE:
1364                 return EXPP_setIValueRange( value, &con->type, 0, 
1365                         EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
1366         default:
1367                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1368         }
1369 }
1370
1371 static PyObject *childof_getter( BPy_Constraint * self, int type )
1372 {
1373         bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1374
1375         switch( type ) {
1376         case EXPP_CONSTR_TARGET:
1377                 return Object_CreatePyObject( con->tar );
1378         case EXPP_CONSTR_BONE:
1379                 return PyString_FromString( con->subtarget );
1380         case EXPP_CONSTR_COPY:
1381                 return PyInt_FromLong( (long)con->flag );
1382         default:
1383                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1384         }
1385 }
1386
1387 static int childof_setter( BPy_Constraint *self, int type, PyObject *value )
1388 {
1389         bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1390
1391         switch( type ) {
1392         case EXPP_CONSTR_TARGET: {
1393                 Object *obj = (( BPy_Object * )value)->object;
1394                 if( !BPy_Object_Check( value ) )
1395                         return EXPP_ReturnIntError( PyExc_TypeError, 
1396                                         "expected BPy object argument" );
1397                 con->tar = obj;
1398                 return 0;
1399                 }
1400         case EXPP_CONSTR_BONE: {
1401                 char *name = PyString_AsString( value );
1402                 if( !name )
1403                         return EXPP_ReturnIntError( PyExc_TypeError,
1404                                         "expected string arg" );
1405
1406                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1407
1408                 return 0;
1409                 }
1410         case EXPP_CONSTR_COPY:
1411                 return EXPP_setIValueRange( value, &con->flag,
1412                                 0, CHILDOF_LOCX| CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ |
1413                                         CHILDOF_SIZEX |CHILDOF_SIZEY| CHILDOF_SIZEZ, 'i' );
1414         default:
1415                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1416         }
1417 }
1418
1419 static PyObject *transf_getter( BPy_Constraint * self, int type )
1420 {
1421         bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1422
1423         switch( type ) {
1424         case EXPP_CONSTR_TARGET:
1425                 return Object_CreatePyObject( con->tar );
1426         case EXPP_CONSTR_BONE:
1427                 return PyString_FromString( con->subtarget );
1428         case EXPP_CONSTR_FROM:
1429                 return PyInt_FromLong( (long)con->from );
1430         case EXPP_CONSTR_TO:
1431                 return PyInt_FromLong( (long)con->to );
1432         case EXPP_CONSTR_MAPX:
1433                 return PyInt_FromLong( (long)con->map[0] );
1434         case EXPP_CONSTR_MAPY:
1435                 return PyInt_FromLong( (long)con->map[1] );
1436         case EXPP_CONSTR_MAPZ:
1437                 return PyInt_FromLong( (long)con->map[2] );
1438         case EXPP_CONSTR_FROMMINX:
1439                 return PyFloat_FromDouble( (double)con->from_min[0] );
1440         case EXPP_CONSTR_FROMMAXX:
1441                 return PyFloat_FromDouble( (double)con->from_max[0] );
1442         case EXPP_CONSTR_FROMMINY:
1443                 return PyFloat_FromDouble( (double)con->from_min[1] );
1444         case EXPP_CONSTR_FROMMAXY:
1445                 return PyFloat_FromDouble( (double)con->from_max[1] );
1446         case EXPP_CONSTR_FROMMINZ:
1447                 return PyFloat_FromDouble( (double)con->from_min[2] );
1448         case EXPP_CONSTR_FROMMAXZ:
1449                 return PyFloat_FromDouble( (double)con->from_max[2] );
1450         case EXPP_CONSTR_TOMINX:
1451                 return PyFloat_FromDouble( (double)con->to_min[0] );
1452         case EXPP_CONSTR_TOMAXX:
1453                 return PyFloat_FromDouble( (double)con->to_max[0] );
1454         case EXPP_CONSTR_TOMINY:
1455                 return PyFloat_FromDouble( (double)con->to_min[1] );
1456         case EXPP_CONSTR_TOMAXY:
1457                 return PyFloat_FromDouble( (double)con->to_max[1] );
1458         case EXPP_CONSTR_TOMINZ:
1459                 return PyFloat_FromDouble( (double)con->to_min[2] );
1460         case EXPP_CONSTR_TOMAXZ:
1461                 return PyFloat_FromDouble( (double)con->to_max[2] );
1462         case EXPP_CONSTR_EXPO:
1463                 return PyBool_FromLong( (long)con->expo );
1464         default:
1465                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1466         }
1467 }
1468
1469 static int transf_setter( BPy_Constraint *self, int type, PyObject *value )
1470 {
1471         bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1472         float fmin, fmax, tmin, tmax;
1473         
1474         if (con->from == 2) {
1475                 fmin = 0.0001;
1476                 fmax = 1000.0;
1477         }
1478         else if (con->from == 1) {
1479                 fmin = -360.0;
1480                 fmax = 360.0;
1481         }
1482         else {
1483                 fmin = -1000.0;
1484                 fmax = 1000.0;
1485         }
1486         
1487         if (con->to == 2) {
1488                 tmin = 0.0001;
1489                 tmax = 1000.0;
1490         }
1491         else if (con->to == 1) {
1492                 tmin = -360.0;
1493                 tmax = 360.0;
1494         }
1495         else {
1496                 tmin = -1000.0;
1497                 tmax = 1000.0;
1498         }
1499         
1500         switch( type ) {
1501         case EXPP_CONSTR_TARGET: {
1502                 Object *obj = (( BPy_Object * )value)->object;
1503                 if( !BPy_Object_Check( value ) )
1504                         return EXPP_ReturnIntError( PyExc_TypeError, 
1505                                         "expected BPy object argument" );
1506                 con->tar = obj;
1507                 return 0;
1508                 }
1509         case EXPP_CONSTR_BONE: {
1510                 char *name = PyString_AsString( value );
1511                 if( !name )
1512                         return EXPP_ReturnIntError( PyExc_TypeError,
1513                                         "expected string arg" );
1514
1515                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1516
1517                 return 0;
1518                 }
1519         case EXPP_CONSTR_FROM:
1520                 return EXPP_setIValueClamped( value, &con->from, 0, 3, 'h' );
1521         case EXPP_CONSTR_TO:
1522                 return EXPP_setIValueClamped( value, &con->to, 0, 3, 'h' );
1523         case EXPP_CONSTR_MAPX:
1524                 return EXPP_setIValueClamped( value, &con->map[0], 0, 3, 'h' );
1525         case EXPP_CONSTR_MAPY:
1526                 return EXPP_setIValueClamped( value, &con->map[1], 0, 3, 'h' );
1527         case EXPP_CONSTR_MAPZ:
1528                 return EXPP_setIValueClamped( value, &con->map[2], 0, 3, 'h' );
1529         case EXPP_CONSTR_FROMMINX:
1530                 return EXPP_setFloatClamped( value, &con->from_min[0], fmin, fmax );
1531         case EXPP_CONSTR_FROMMAXX:
1532                 return EXPP_setFloatClamped( value, &con->from_max[0], fmin, fmax );
1533         case EXPP_CONSTR_FROMMINY:
1534                 return EXPP_setFloatClamped( value, &con->from_min[1], fmin, fmax );
1535         case EXPP_CONSTR_FROMMAXY:
1536                 return EXPP_setFloatClamped( value, &con->from_max[1], fmin, fmax );
1537         case EXPP_CONSTR_FROMMINZ:
1538                 return EXPP_setFloatClamped( value, &con->from_min[2], fmin, fmax );
1539         case EXPP_CONSTR_FROMMAXZ:
1540                 return EXPP_setFloatClamped( value, &con->from_max[2], fmin, fmax );
1541         case EXPP_CONSTR_TOMINX:
1542                 return EXPP_setFloatClamped( value, &con->to_min[0], tmin, tmax );
1543         case EXPP_CONSTR_TOMAXX:
1544                 return EXPP_setFloatClamped( value, &con->to_max[0], tmin, tmax );
1545         case EXPP_CONSTR_TOMINY:
1546                 return EXPP_setFloatClamped( value, &con->to_min[1], tmin, tmax );
1547         case EXPP_CONSTR_TOMAXY:
1548                 return EXPP_setFloatClamped( value, &con->to_max[1], tmin, tmax );
1549         case EXPP_CONSTR_TOMINZ:
1550                 return EXPP_setFloatClamped( value, &con->to_min[2], tmin, tmax );
1551         case EXPP_CONSTR_TOMAXZ:
1552                 return EXPP_setFloatClamped( value, &con->to_max[2], tmin, tmax );
1553         case EXPP_CONSTR_EXPO:
1554                 return EXPP_setBitfield( value, &con->expo, 1, 'h' );
1555         default:
1556                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1557         }
1558 }
1559
1560 /*
1561  * get data from a constraint
1562  */
1563
1564 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
1565 {
1566         int setting;
1567
1568         if( !PyInt_Check( key ) )
1569                 return EXPP_ReturnPyObjError( PyExc_TypeError,
1570                                 "expected an int arg" );
1571
1572         if( !self->con )
1573                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1574                                 "This constraint has been removed!" );
1575         
1576         setting = PyInt_AsLong( key );
1577         switch( self->con->type ) {
1578                 case CONSTRAINT_TYPE_NULL:
1579                         Py_RETURN_NONE;
1580                 case CONSTRAINT_TYPE_TRACKTO:
1581                         return trackto_getter( self, setting );
1582                 case CONSTRAINT_TYPE_KINEMATIC:
1583                         return kinematic_getter( self, setting );
1584                 case CONSTRAINT_TYPE_FOLLOWPATH:
1585                         return followpath_getter( self, setting );
1586                 case CONSTRAINT_TYPE_ACTION:
1587                         return action_getter( self, setting );
1588                 case CONSTRAINT_TYPE_LOCKTRACK:
1589                         return locktrack_getter( self, setting );
1590                 case CONSTRAINT_TYPE_STRETCHTO:
1591                         return stretchto_getter( self, setting );
1592                 case CONSTRAINT_TYPE_MINMAX:
1593                         return floor_getter( self, setting );
1594                 case CONSTRAINT_TYPE_LOCLIKE:
1595                         return locatelike_getter( self, setting );
1596                 case CONSTRAINT_TYPE_ROTLIKE:
1597                         return rotatelike_getter( self, setting );
1598                 case CONSTRAINT_TYPE_SIZELIKE:
1599                         return sizelike_getter( self, setting );
1600                 case CONSTRAINT_TYPE_ROTLIMIT:
1601                         return rotlimit_getter( self, setting );
1602                 case CONSTRAINT_TYPE_LOCLIMIT:
1603                         return loclimit_getter( self, setting );
1604                 case CONSTRAINT_TYPE_SIZELIMIT:
1605                         return sizelimit_getter( self, setting );
1606                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1607                         return rigidbody_getter( self, setting );
1608                 case CONSTRAINT_TYPE_CLAMPTO:
1609                         return clampto_getter( self, setting );
1610                 case CONSTRAINT_TYPE_PYTHON:
1611                         return script_getter( self, setting );
1612                 case CONSTRAINT_TYPE_CHILDOF:
1613                         return childof_getter( self, setting );
1614                 case CONSTRAINT_TYPE_TRANSFORM:
1615                         return transf_getter( self, setting );
1616                 default:
1617                         return EXPP_ReturnPyObjError( PyExc_KeyError,
1618                                         "unknown constraint type" );
1619         }
1620 }
1621
1622 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
1623                 PyObject * arg )
1624 {
1625         int key_int, result;
1626
1627         if( !PyNumber_Check( key ) )
1628                 return EXPP_ReturnIntError( PyExc_TypeError,
1629                                 "expected an int arg" );
1630         if( !self->con )
1631                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1632                                 "This constraint has been removed!" );
1633         
1634         key_int = PyInt_AsLong( key );
1635         switch( self->con->type ) {
1636         case CONSTRAINT_TYPE_KINEMATIC:
1637                 result = kinematic_setter( self, key_int, arg );
1638                 break;
1639         case CONSTRAINT_TYPE_ACTION:
1640                 result = action_setter( self, key_int, arg );
1641                 break;
1642         case CONSTRAINT_TYPE_TRACKTO:
1643                 result = trackto_setter( self, key_int, arg );
1644                 break;
1645         case CONSTRAINT_TYPE_STRETCHTO:
1646                 result = stretchto_setter( self, key_int, arg );
1647                 break;
1648         case CONSTRAINT_TYPE_FOLLOWPATH:
1649                 result = followpath_setter( self, key_int, arg );
1650                 break;
1651         case CONSTRAINT_TYPE_LOCKTRACK:
1652                 result = locktrack_setter( self, key_int, arg );
1653                 break;
1654         case CONSTRAINT_TYPE_MINMAX:
1655                 result = floor_setter( self, key_int, arg );
1656                 break;
1657         case CONSTRAINT_TYPE_LOCLIKE:
1658                 result = locatelike_setter( self, key_int, arg );
1659                 break;
1660         case CONSTRAINT_TYPE_ROTLIKE:
1661                 result = rotatelike_setter( self, key_int, arg );
1662                 break;
1663         case CONSTRAINT_TYPE_SIZELIKE:
1664                 result = sizelike_setter( self, key_int, arg );
1665                 break;
1666         case CONSTRAINT_TYPE_ROTLIMIT:
1667                 result = rotlimit_setter( self, key_int, arg );
1668                 break;
1669         case CONSTRAINT_TYPE_LOCLIMIT:
1670                 result = loclimit_setter( self, key_int, arg );
1671                 break;
1672         case CONSTRAINT_TYPE_SIZELIMIT:
1673                 result = sizelimit_setter( self, key_int, arg);
1674                 break;
1675         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1676                 result = rigidbody_setter( self, key_int, arg);
1677                 break;
1678         case CONSTRAINT_TYPE_CLAMPTO:
1679                 result = clampto_setter( self, key_int, arg);
1680                 break;
1681         case CONSTRAINT_TYPE_PYTHON:
1682                 result = script_setter( self, key_int, arg);
1683                 break;
1684         case CONSTRAINT_TYPE_CHILDOF:
1685                 result = childof_setter( self, key_int, arg);
1686                 break;
1687         case CONSTRAINT_TYPE_TRANSFORM:
1688                 result = transf_setter( self, key_int, arg);
1689                 break;
1690         case CONSTRAINT_TYPE_NULL:
1691                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1692         default:
1693                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1694                                 "unsupported constraint setting" );
1695         }
1696         if( !result && self->pchan )
1697                 update_pose_constraint_flags( self->obj->pose );
1698         return result;
1699 }
1700
1701 /*****************************************************************************/
1702 /* Function:    Constraint_compare                                           */
1703 /* Description: This compares 2 constraint python types, == or != only.      */
1704 /*****************************************************************************/
1705 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
1706 {
1707         return ( a->con == b->con ) ? 0 : -1;
1708 }
1709
1710 /*****************************************************************************/
1711 /* Function:    Constraint_repr                                              */
1712 /* Description: This is a callback function for the BPy_Constraint type. It  */
1713 /*              builds a meaningful string to represent constraint objects.  */
1714 /*****************************************************************************/
1715
1716 static PyObject *Constraint_repr( BPy_Constraint * self )
1717 {
1718         char type[32];
1719
1720         if( !self->con )
1721                 return PyString_FromString( "[Constraint - Removed]");
1722
1723         get_constraint_typestring (type,  self->con);
1724         return PyString_FromFormat( "[Constraint \"%s\", Type \"%s\"]",
1725                         self->con->name, type );
1726 }
1727
1728 /* Three Python Constraint_Type helper functions needed by the Object module: */
1729
1730 /*****************************************************************************/
1731 /* Function:    Constraint_CreatePyObject                                    */
1732 /* Description: This function will create a new BPy_Constraint from an       */
1733 /*              existing Blender constraint structure.                       */
1734 /*****************************************************************************/
1735 PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
1736                 bConstraint *con )
1737 {
1738         BPy_Constraint *pycon;
1739         pycon = ( BPy_Constraint * ) PyObject_NEW( BPy_Constraint,
1740                         &Constraint_Type );
1741         if( !pycon )
1742                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1743                                               "couldn't create BPy_Constraint object" );
1744
1745         pycon->con = con;
1746
1747         /* one of these two will be NULL */
1748         pycon->obj = obj;       
1749         pycon->pchan = pchan;
1750         return ( PyObject * ) pycon;
1751 }
1752
1753 /*****************************************************************************/
1754 /* Function:    Constraint_FromPyObject                                      */
1755 /* Description: This function returns the Blender constraint from the given  */
1756 /*              PyObject.                                                    */
1757 /*****************************************************************************/
1758 bConstraint *Constraint_FromPyObject( BPy_Constraint * self )
1759 {
1760         return self->con;
1761 }
1762
1763 /*****************************************************************************/
1764 /* Constraint Sequence wrapper                                               */
1765 /*****************************************************************************/
1766
1767 /*
1768  * Initialize the interator
1769  */
1770
1771 static PyObject *ConstraintSeq_getIter( BPy_ConstraintSeq * self )
1772 {
1773         if( self->pchan )
1774                 self->iter = (bConstraint *)self->pchan->constraints.first;
1775         else
1776                 self->iter = (bConstraint *)self->obj->constraints.first;
1777         return EXPP_incr_ret ( (PyObject *) self );
1778 }
1779
1780 /*
1781  * Get the next Constraint
1782  */
1783
1784 static PyObject *ConstraintSeq_nextIter( BPy_ConstraintSeq * self )
1785 {
1786         bConstraint *this = self->iter;
1787         if( this ) {
1788                 self->iter = this->next;
1789                 return Constraint_CreatePyObject( self->pchan, self->obj, this );
1790         }
1791
1792         return EXPP_ReturnPyObjError( PyExc_StopIteration,
1793                         "iterator at end" );
1794 }
1795
1796 /* return the number of constraints */
1797
1798 static int ConstraintSeq_length( BPy_ConstraintSeq * self )
1799 {
1800         return BLI_countlist( self->pchan ?
1801                 &self->pchan->constraints : &self->obj->constraints );
1802 }
1803
1804 /* return a constraint */
1805
1806 static PyObject *ConstraintSeq_item( BPy_ConstraintSeq * self, int i )
1807 {
1808         bConstraint *con = NULL;
1809
1810         /* if index is negative, start counting from the end of the list */
1811         if( i < 0 )
1812                 i += ConstraintSeq_length( self );
1813
1814         /* skip through the list until we get the constraint or end of list */
1815
1816         if( self->pchan )
1817                 con = self->pchan->constraints.first;
1818         else
1819                 con = self->obj->constraints.first;
1820
1821         while( i && con ) {
1822                 --i;
1823                 con = con->next;
1824         }
1825
1826         if( con )
1827                 return Constraint_CreatePyObject( self->pchan, self->obj, con );
1828         else
1829                 return EXPP_ReturnPyObjError( PyExc_IndexError,
1830                                 "array index out of range" );
1831 }
1832
1833 /*****************************************************************************/
1834 /* Python BPy_ConstraintSeq sequence table:                                  */
1835 /*****************************************************************************/
1836 static PySequenceMethods ConstraintSeq_as_sequence = {
1837         ( inquiry ) ConstraintSeq_length,       /* sq_length */
1838         ( binaryfunc ) 0,       /* sq_concat */
1839         ( intargfunc ) 0,       /* sq_repeat */
1840         ( intargfunc ) ConstraintSeq_item,      /* sq_item */
1841         ( intintargfunc ) 0,    /* sq_slice */
1842         ( intobjargproc ) 0,    /* sq_ass_item */
1843         ( intintobjargproc ) 0, /* sq_ass_slice */
1844         ( objobjproc ) 0,       /* sq_contains */
1845         ( binaryfunc ) 0,               /* sq_inplace_concat */
1846         ( intargfunc ) 0,               /* sq_inplace_repeat */
1847 };
1848
1849 /*
1850  * helper function to check for a valid constraint argument
1851  */
1852
1853 static bConstraint *locate_constr( BPy_ConstraintSeq *self, BPy_Constraint * value )
1854 {
1855         bConstraint *con;
1856
1857         /* check that argument is a modifier */
1858         if (!BPy_Constraint_Check(value))
1859                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
1860                                 "expected a constraint as an argument" );
1861
1862         /* check whether constraint has been removed */
1863         if( !value->con )
1864                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
1865                                 "This constraint has been removed!" );
1866
1867         /* verify the constraint is still exists in the stack */
1868         if( self->pchan )
1869                 con = self->pchan->constraints.first;
1870         else
1871                 con = self->obj->constraints.first;
1872         while( con && con != value->con )
1873                 con = con->next;
1874
1875         /* if we didn't find it, exception */
1876         if( !con )
1877                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
1878                                 "This constraint is no longer in the object's stack" );
1879
1880         return con;
1881 }
1882
1883
1884 /* create a new constraint at the end of the list */
1885
1886 static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *value )
1887 {
1888         int type = (int)PyInt_AsLong(value);
1889         bConstraint *con;
1890
1891         /* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these?
1892          * if the value is not an int it will be -1 */
1893         if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT ) 
1894                 return EXPP_ReturnPyObjError( PyExc_ValueError,
1895                                 "arg not in int or out of range" );
1896
1897         con = add_new_constraint( type );
1898         if( self->pchan ) {
1899                 BLI_addtail( &self->pchan->constraints, con );
1900                 update_pose_constraint_flags( self->obj->pose );
1901         }
1902         else
1903                 BLI_addtail( &self->obj->constraints, con );
1904
1905         return Constraint_CreatePyObject( self->pchan, self->obj, con );
1906 }
1907
1908 /* move the constraint up in the stack */
1909
1910 static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, BPy_Constraint *value )
1911 {
1912         bConstraint *con = locate_constr( self,  value );
1913
1914         /* if we can't locate the constraint, return (exception already set) */
1915         if( !con )
1916                 return (PyObject *)NULL;
1917
1918         const_moveUp( self->obj, con );
1919         Py_RETURN_NONE;
1920 }
1921
1922 /* move the constraint down in the stack */
1923
1924 static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, BPy_Constraint *value )
1925 {
1926         bConstraint *con = locate_constr( self,  value );
1927
1928         /* if we can't locate the constraint, return (exception already set) */
1929         if( !con )
1930                 return (PyObject *)NULL;
1931
1932         const_moveDown( self->obj, con );
1933         Py_RETURN_NONE;
1934 }
1935
1936 /* remove an existing constraint */
1937
1938 static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, BPy_Constraint *value )
1939 {
1940         bConstraint *con = locate_constr( self,  value );
1941
1942         /* if we can't locate the constraint, return (exception already set) */
1943         if( !con )
1944                 return (PyObject *)NULL;
1945
1946         /* do the actual removal */
1947         if( self->pchan )
1948                 BLI_remlink( &self->pchan->constraints, con );
1949         else
1950                 BLI_remlink( &self->obj->constraints, con);
1951         del_constr_func( self->obj, con );
1952
1953         /* erase the link to the constraint */
1954         value->con = NULL;
1955
1956         Py_RETURN_NONE;
1957 }
1958
1959 /*****************************************************************************/
1960 /* Function:    ConstraintSeq_dealloc                                        */
1961 /* Description: This is a callback function for the BPy_ConstraintSeq type.  */
1962 /*              It destroys data when the object is deleted.                 */
1963 /*****************************************************************************/
1964 static void ConstraintSeq_dealloc( BPy_Constraint * self )
1965 {
1966         PyObject_DEL( self );
1967 }
1968
1969 /*****************************************************************************/
1970 /* Python BPy_ConstraintSeq methods table:                                   */
1971 /*****************************************************************************/
1972 static PyMethodDef BPy_ConstraintSeq_methods[] = {
1973         /* name, method, flags, doc */
1974         {"append", ( PyCFunction ) ConstraintSeq_append, METH_O,
1975          "(type) - add a new constraint, where type is the constraint type"},
1976         {"remove", ( PyCFunction ) ConstraintSeq_remove, METH_O,
1977          "(con) - remove an existing constraint, where con is a constraint from this object."},
1978         {"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_O,
1979          "(con) - Move constraint up in stack"},
1980         {"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_O,
1981          "(con) - Move constraint down in stack"},
1982         {NULL, NULL, 0, NULL}
1983 };
1984
1985 /*****************************************************************************/
1986 /* Python ConstraintSeq_Type structure definition:                           */
1987 /*****************************************************************************/
1988 PyTypeObject ConstraintSeq_Type = {
1989         PyObject_HEAD_INIT( NULL )  /* required py macro */
1990         0,                          /* ob_size */
1991         /*  For printing, in format "<module>.<name>" */
1992         "Blender.Constraints",      /* char *tp_name; */
1993         sizeof( BPy_ConstraintSeq ),     /* int tp_basicsize; */
1994         0,                          /* tp_itemsize;  For allocation */
1995
1996         /* Methods to implement standard operations */
1997
1998         ( destructor ) ConstraintSeq_dealloc,/* destructor tp_dealloc; */
1999         NULL,                       /* printfunc tp_print; */
2000         NULL,                       /* getattrfunc tp_getattr; */
2001         NULL,                       /* setattrfunc tp_setattr; */
2002         NULL,                       /* cmpfunc tp_compare; */
2003         ( reprfunc ) NULL,          /* reprfunc tp_repr; */
2004
2005         /* Method suites for standard classes */
2006
2007         NULL,                       /* PyNumberMethods *tp_as_number; */
2008         &ConstraintSeq_as_sequence,        /* PySequenceMethods *tp_as_sequence; */
2009         NULL,                       /* PyMappingMethods *tp_as_mapping; */
2010
2011         /* More standard operations (here for binary compatibility) */
2012
2013         NULL,                       /* hashfunc tp_hash; */
2014         NULL,                       /* ternaryfunc tp_call; */
2015         NULL,                       /* reprfunc tp_str; */
2016         NULL,                       /* getattrofunc tp_getattro; */
2017         NULL,                       /* setattrofunc tp_setattro; */
2018
2019         /* Functions to access object as input/output buffer */
2020         NULL,                       /* PyBufferProcs *tp_as_buffer; */
2021
2022   /*** Flags to define presence of optional/expanded features ***/
2023         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
2024
2025         NULL,                       /*  char *tp_doc;  Documentation string */
2026   /*** Assigned meaning in release 2.0 ***/
2027         /* call function for all accessible objects */
2028         NULL,                       /* traverseproc tp_traverse; */
2029
2030         /* delete references to contained objects */
2031         NULL,                       /* inquiry tp_clear; */
2032
2033   /***  Assigned meaning in release 2.1 ***/
2034   /*** rich comparisons ***/
2035         NULL,                       /* richcmpfunc tp_richcompare; */
2036
2037   /***  weak reference enabler ***/
2038         0,                          /* long tp_weaklistoffset; */
2039
2040   /*** Added in release 2.2 ***/
2041         /*   Iterators */
2042         ( getiterfunc )ConstraintSeq_getIter, /* getiterfunc tp_iter; */
2043     ( iternextfunc )ConstraintSeq_nextIter, /* iternextfunc tp_iternext; */
2044
2045   /*** Attribute descriptor and subclassing stuff ***/
2046         BPy_ConstraintSeq_methods,         /* struct PyMethodDef *tp_methods; */
2047         NULL,                       /* struct PyMemberDef *tp_members; */
2048         NULL,                       /* struct PyGetSetDef *tp_getset; */
2049         NULL,                       /* struct _typeobject *tp_base; */
2050         NULL,                       /* PyObject *tp_dict; */
2051         NULL,                       /* descrgetfunc tp_descr_get; */
2052         NULL,                       /* descrsetfunc tp_descr_set; */
2053         0,                          /* long tp_dictoffset; */
2054         NULL,                       /* initproc tp_init; */
2055         NULL,                       /* allocfunc tp_alloc; */
2056         NULL,                       /* newfunc tp_new; */
2057         /*  Low-level free-memory routine */
2058         NULL,                       /* freefunc tp_free;  */
2059         /* For PyObject_IS_GC */
2060         NULL,                       /* inquiry tp_is_gc;  */
2061         NULL,                       /* PyObject *tp_bases; */
2062         /* method resolution order */
2063         NULL,                       /* PyObject *tp_mro;  */
2064         NULL,                       /* PyObject *tp_cache; */
2065         NULL,                       /* PyObject *tp_subclasses; */
2066         NULL,                       /* PyObject *tp_weaklist; */
2067         NULL
2068 };
2069
2070 /*****************************************************************************/
2071 /* Function:    PoseConstraintSeq_CreatePyObject                             */
2072 /* Description: This function will create a new BPy_ConstraintSeq from an    */
2073 /*              existing ListBase structure.                                 */
2074 /*****************************************************************************/
2075 PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan )
2076 {
2077         BPy_ConstraintSeq *pyseq;
2078         Object *ob;
2079
2080         for( ob = G.main->object.first; ob; ob = ob->id.next ) {
2081                 if( ob->type == OB_ARMATURE ) {
2082                         bPoseChannel *p = ob->pose->chanbase.first;
2083                         while( p ) {
2084                                 if( p == pchan ) {
2085                                         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( 
2086                                                         BPy_ConstraintSeq, &ConstraintSeq_Type );
2087                                         if( !pyseq )
2088                                                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2089                                                                 "couldn't create BPy_ConstraintSeq object" );
2090                                         pyseq->pchan = pchan;
2091                                         pyseq->obj = ob;
2092                                         return ( PyObject * ) pyseq;
2093                                 } else
2094                                         p = p->next;
2095                         }
2096                 }
2097         }
2098         return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2099                         "couldn't find ANY armature with the pose!" );
2100
2101 }
2102
2103 /*****************************************************************************/
2104 /* Function:    ObConstraintSeq_CreatePyObject                               */
2105 /* Description: This function will create a new BPy_ConstraintSeq from an    */
2106 /*              existing ListBase structure.                                 */
2107 /*****************************************************************************/
2108 PyObject *ObConstraintSeq_CreatePyObject( Object *obj )
2109 {
2110         BPy_ConstraintSeq *pyseq;
2111         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( BPy_ConstraintSeq,
2112                         &ConstraintSeq_Type );
2113         if( !pyseq )
2114                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2115                                               "couldn't create BPy_ConstraintSeq object" );
2116         pyseq->obj = obj;
2117         pyseq->pchan = NULL;
2118         return ( PyObject * ) pyseq;
2119 }
2120
2121 static PyObject *M_Constraint_TypeDict( void )
2122 {
2123         PyObject *S = PyConstant_New(  );
2124
2125         if( S ) {
2126                 BPy_constant *d = ( BPy_constant * ) S;
2127                 PyConstant_Insert( d, "NULL", 
2128                                 PyInt_FromLong( CONSTRAINT_TYPE_NULL ) );
2129                 PyConstant_Insert( d, "TRACKTO",
2130                                 PyInt_FromLong( CONSTRAINT_TYPE_TRACKTO ) );
2131                 PyConstant_Insert( d, "IKSOLVER", 
2132                                 PyInt_FromLong( CONSTRAINT_TYPE_KINEMATIC ) );
2133                 PyConstant_Insert( d, "FOLLOWPATH", 
2134                                 PyInt_FromLong( CONSTRAINT_TYPE_FOLLOWPATH ) );
2135                 PyConstant_Insert( d, "COPYROT", 
2136                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIKE ) );
2137                 PyConstant_Insert( d, "COPYLOC", 
2138                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIKE ) );
2139                 PyConstant_Insert( d, "COPYSIZE", 
2140                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIKE ) );
2141                 PyConstant_Insert( d, "ACTION", 
2142                                 PyInt_FromLong( CONSTRAINT_TYPE_ACTION ) );
2143                 PyConstant_Insert( d, "LOCKTRACK", 
2144                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCKTRACK ) );
2145                 PyConstant_Insert( d, "STRETCHTO", 
2146                                 PyInt_FromLong( CONSTRAINT_TYPE_STRETCHTO ) );
2147                 PyConstant_Insert( d, "FLOOR", 
2148                                 PyInt_FromLong( CONSTRAINT_TYPE_MINMAX ) );
2149                 PyConstant_Insert( d, "LIMITLOC", 
2150                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIMIT ) );
2151                 PyConstant_Insert( d, "LIMITROT", 
2152                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
2153                 PyConstant_Insert( d, "LIMITSIZE", 
2154                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
2155                 PyConstant_Insert( d, "RIGIDBODYJOINT", 
2156                                 PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
2157                 PyConstant_Insert( d, "CLAMPTO", 
2158                                 PyInt_FromLong( CONSTRAINT_TYPE_CLAMPTO ) );
2159                 PyConstant_Insert( d, "PYTHON",
2160                                 PyInt_FromLong( CONSTRAINT_TYPE_PYTHON ) );
2161                 PyConstant_Insert( d, "CHILDOF",
2162                                 PyInt_FromLong( CONSTRAINT_TYPE_CHILDOF ) );
2163                 PyConstant_Insert( d, "TRANSFORM",
2164                                 PyInt_FromLong( CONSTRAINT_TYPE_TRANSFORM ) );
2165         }
2166         return S;
2167 }
2168
2169 static PyObject *M_Constraint_SettingsDict( void )
2170 {
2171         PyObject *S = PyConstant_New(  );
2172         
2173         if( S ) {
2174                 BPy_constant *d = ( BPy_constant * ) S;
2175                 PyConstant_Insert( d, "XROT",
2176                                 PyInt_FromLong( EXPP_CONSTR_XROT ) );
2177                 PyConstant_Insert( d, "YROT",
2178                                 PyInt_FromLong( EXPP_CONSTR_YROT ) );
2179                 PyConstant_Insert( d, "ZROT",
2180                                 PyInt_FromLong( EXPP_CONSTR_ZROT ) );
2181                 PyConstant_Insert( d, "XSIZE",
2182                                 PyInt_FromLong( EXPP_CONSTR_XSIZE ) );
2183                 PyConstant_Insert( d, "YSIZE",
2184                                 PyInt_FromLong( EXPP_CONSTR_YSIZE ) );
2185                 PyConstant_Insert( d, "ZSIZE",
2186                                 PyInt_FromLong( EXPP_CONSTR_ZSIZE ) );
2187                 PyConstant_Insert( d, "XLOC",
2188                                 PyInt_FromLong( EXPP_CONSTR_XLOC ) );
2189                 PyConstant_Insert( d, "YLOC",
2190                                 PyInt_FromLong( EXPP_CONSTR_YLOC ) );
2191                 PyConstant_Insert( d, "ZLOC",
2192                                 PyInt_FromLong( EXPP_CONSTR_ZLOC ) );
2193
2194                 PyConstant_Insert( d, "UPX",
2195                                 PyInt_FromLong( UP_X ) );
2196                 PyConstant_Insert( d, "UPY",
2197                                 PyInt_FromLong( UP_Y ) );
2198                 PyConstant_Insert( d, "UPZ",
2199                                 PyInt_FromLong( UP_Z ) );
2200
2201                 PyConstant_Insert( d, "TRACKX",
2202                                 PyInt_FromLong( TRACK_X ) );
2203                 PyConstant_Insert( d, "TRACKY",
2204                                 PyInt_FromLong( TRACK_Y ) );
2205                 PyConstant_Insert( d, "TRACKZ",
2206                                 PyInt_FromLong( TRACK_Z ) );
2207                 PyConstant_Insert( d, "TRACKNEGX",
2208                                 PyInt_FromLong( TRACK_nX ) );
2209                 PyConstant_Insert( d, "TRACKNEGY",
2210                                 PyInt_FromLong( TRACK_nY ) );
2211                 PyConstant_Insert( d, "TRACKNEGZ",
2212                                 PyInt_FromLong( TRACK_nZ ) );
2213
2214                 PyConstant_Insert( d, "VOLUMEXZ",
2215                                 PyInt_FromLong( VOLUME_XZ ) );
2216                 PyConstant_Insert( d, "VOLUMEX",
2217                                 PyInt_FromLong( VOLUME_X ) );
2218                 PyConstant_Insert( d, "VOLUMEZ",
2219                                 PyInt_FromLong( VOLUME_Z ) );
2220                 PyConstant_Insert( d, "VOLUMENONE",
2221                                 PyInt_FromLong( NO_VOLUME ) );
2222
2223                 PyConstant_Insert( d, "PLANEX",
2224                                 PyInt_FromLong( PLANE_X ) );
2225                 PyConstant_Insert( d, "PLANEY",
2226                                 PyInt_FromLong( PLANE_Y ) );
2227                 PyConstant_Insert( d, "PLANEZ",
2228                                 PyInt_FromLong( PLANE_Z ) );
2229
2230                 PyConstant_Insert( d, "LOCKX",
2231                                 PyInt_FromLong( LOCK_X ) );
2232                 PyConstant_Insert( d, "LOCKY",
2233                                 PyInt_FromLong( LOCK_Y ) );
2234                 PyConstant_Insert( d, "LOCKZ",
2235                                 PyInt_FromLong( LOCK_Z ) );
2236
2237                 PyConstant_Insert( d, "MAXX",
2238                                 PyInt_FromLong( EXPP_CONSTR_MAXX ) );
2239                 PyConstant_Insert( d, "MAXY",
2240                                 PyInt_FromLong( EXPP_CONSTR_MAXY ) );
2241                 PyConstant_Insert( d, "MAXZ",
2242                                 PyInt_FromLong( EXPP_CONSTR_MAXZ ) );
2243                 PyConstant_Insert( d, "MINX",
2244                                 PyInt_FromLong( EXPP_CONSTR_MINX ) );
2245                 PyConstant_Insert( d, "MINY",
2246                                 PyInt_FromLong( EXPP_CONSTR_MINY ) );
2247                 PyConstant_Insert( d, "MINZ",
2248                                 PyInt_FromLong( EXPP_CONSTR_MINZ ) );
2249
2250                 PyConstant_Insert( d, "COPYX",
2251                                 PyInt_FromLong( LOCLIKE_X ) );
2252                 PyConstant_Insert( d, "COPYY",
2253                                 PyInt_FromLong( LOCLIKE_Y ) );
2254                 PyConstant_Insert( d, "COPYZ",
2255                                 PyInt_FromLong( LOCLIKE_Z ) );
2256                 PyConstant_Insert( d, "COPYXINVERT",
2257                                 PyInt_FromLong( LOCLIKE_X_INVERT ) );
2258                 PyConstant_Insert( d, "COPYYINVERT",
2259                                 PyInt_FromLong( LOCLIKE_Y_INVERT ) );
2260                 PyConstant_Insert( d, "COPYZINVERT",
2261                                 PyInt_FromLong( LOCLIKE_Z_INVERT ) );
2262                                 
2263                 PyConstant_Insert( d, "PARLOCX",
2264                                 PyInt_FromLong( CHILDOF_LOCX ) );
2265                 PyConstant_Insert( d, "PARLOCY",
2266                                 PyInt_FromLong( CHILDOF_LOCY ) );
2267                 PyConstant_Insert( d, "PARLOCZ",
2268                                 PyInt_FromLong( CHILDOF_LOCZ ) );
2269                 PyConstant_Insert( d, "PARROTX",
2270                                 PyInt_FromLong( CHILDOF_ROTX ) );
2271                 PyConstant_Insert( d, "PARROTY",
2272                                 PyInt_FromLong( CHILDOF_ROTY ) );
2273                 PyConstant_Insert( d, "PARROTZ",
2274                                 PyInt_FromLong( CHILDOF_ROTZ ) );
2275                 PyConstant_Insert( d, "PARSIZEX",
2276                                 PyInt_FromLong( CHILDOF_LOCX ) );
2277                 PyConstant_Insert( d, "PARSIZEY",
2278                                 PyInt_FromLong( CHILDOF_SIZEY ) );
2279                 PyConstant_Insert( d, "PARSIZEZ",
2280                                 PyInt_FromLong( CHILDOF_SIZEZ ) );
2281                                 
2282                 PyConstant_Insert( d, "CLAMPAUTO",
2283                                 PyInt_FromLong( CLAMPTO_AUTO ) );
2284                 PyConstant_Insert( d, "CLAMPX",
2285                                 PyInt_FromLong( CLAMPTO_X ) );
2286                 PyConstant_Insert( d, "CLAMPY",
2287                                 PyInt_FromLong( CLAMPTO_Y ) );
2288                 PyConstant_Insert( d, "CLAMPZ",
2289                                 PyInt_FromLong( CLAMPTO_Z ) );
2290
2291                 PyConstant_Insert( d, "TARGET",
2292                                 PyInt_FromLong( EXPP_CONSTR_TARGET ) );
2293                 PyConstant_Insert( d, "STRETCH", 
2294                                 PyInt_FromLong( EXPP_CONSTR_STRETCH ) );
2295                 PyConstant_Insert( d, "ITERATIONS", 
2296                                 PyInt_FromLong( EXPP_CONSTR_ITERATIONS ) );
2297                 PyConstant_Insert( d, "BONE", 
2298                                 PyInt_FromLong( EXPP_CONSTR_BONE ) );
2299                 PyConstant_Insert( d, "CHAINLEN", 
2300                                 PyInt_FromLong( EXPP_CONSTR_CHAINLEN ) );
2301                 PyConstant_Insert( d, "POSWEIGHT", 
2302                                 PyInt_FromLong( EXPP_CONSTR_POSWEIGHT ) );
2303                 PyConstant_Insert( d, "ROTWEIGHT", 
2304                                 PyInt_FromLong( EXPP_CONSTR_ROTWEIGHT ) );
2305                 PyConstant_Insert( d, "ROTATE", 
2306                                 PyInt_FromLong( EXPP_CONSTR_ROTATE ) );
2307                 PyConstant_Insert( d, "USETIP", 
2308                                 PyInt_FromLong( EXPP_CONSTR_USETIP ) );
2309
2310                 PyConstant_Insert( d, "ACTION", 
2311                                 PyInt_FromLong( EXPP_CONSTR_ACTION ) );
2312                 PyConstant_Insert( d, "START", 
2313                                 PyInt_FromLong( EXPP_CONSTR_START ) );
2314                 PyConstant_Insert( d, "END", 
2315                                 PyInt_FromLong( EXPP_CONSTR_END ) );
2316                 PyConstant_Insert( d, "MIN", 
2317                                 PyInt_FromLong( EXPP_CONSTR_MIN ) );
2318                 PyConstant_Insert( d, "MAX", 
2319                                 PyInt_FromLong( EXPP_CONSTR_MAX ) );
2320                 PyConstant_Insert( d, "KEYON", 
2321                                 PyInt_FromLong( EXPP_CONSTR_KEYON ) );
2322
2323                 PyConstant_Insert( d, "TRACK", 
2324                                 PyInt_FromLong( EXPP_CONSTR_TRACK ) );
2325                 PyConstant_Insert( d, "UP", 
2326                                 PyInt_FromLong( EXPP_CONSTR_UP ) );
2327
2328                 PyConstant_Insert( d, "RESTLENGTH",
2329                                 PyInt_FromLong( EXPP_CONSTR_RESTLENGTH ) );
2330                 PyConstant_Insert( d, "VOLVARIATION",
2331                                 PyInt_FromLong( EXPP_CONSTR_VOLVARIATION ) );
2332                 PyConstant_Insert( d, "VOLUMEMODE",
2333                                 PyInt_FromLong( EXPP_CONSTR_VOLUMEMODE ) );
2334                 PyConstant_Insert( d, "PLANE",
2335                                 PyInt_FromLong( EXPP_CONSTR_PLANE ) );
2336
2337                 PyConstant_Insert( d, "FOLLOW",
2338                                 PyInt_FromLong( EXPP_CONSTR_FOLLOW ) );
2339                 PyConstant_Insert( d, "OFFSET",
2340                                 PyInt_FromLong( EXPP_CONSTR_OFFSET ) );
2341                 PyConstant_Insert( d, "FORWARD",
2342                                 PyInt_FromLong( EXPP_CONSTR_FORWARD ) );
2343
2344                 PyConstant_Insert( d, "LOCK",
2345                                 PyInt_FromLong( EXPP_CONSTR_LOCK ) );
2346
2347                 PyConstant_Insert( d, "COPY",
2348                                 PyInt_FromLong( EXPP_CONSTR_COPY ) );
2349                 PyConstant_Insert( d, "LIMIT",
2350                                 PyInt_FromLong( EXPP_CONSTR_LIMIT ) );
2351                 PyConstant_Insert( d, "CLAMP",
2352                                 PyInt_FromLong( EXPP_CONSTR_CLAMP ) );
2353                 
2354                 PyConstant_Insert( d, "LIMIT_XMIN",
2355                                 PyInt_FromLong( EXPP_CONSTR_LIMXMIN ) );
2356                 PyConstant_Insert( d, "LIMIT_XMAX",
2357                                 PyInt_FromLong( EXPP_CONSTR_LIMXMAX ) );
2358                 PyConstant_Insert( d, "LIMIT_YMIN",
2359                                 PyInt_FromLong( EXPP_CONSTR_LIMYMIN ) );
2360                 PyConstant_Insert( d, "LIMIT_YMAX",
2361                                 PyInt_FromLong( EXPP_CONSTR_LIMYMAX ) );
2362                 PyConstant_Insert( d, "LIMIT_ZMIN",
2363                                 PyInt_FromLong( EXPP_CONSTR_LIMZMIN ) );
2364                 PyConstant_Insert( d, "LIMIT_ZMAX",
2365                                 PyInt_FromLong( EXPP_CONSTR_LIMZMAX ) );
2366                 
2367                 PyConstant_Insert( d, "LIMIT_XROT",
2368                                 PyInt_FromLong( EXPP_CONSTR_LIMXROT ) );
2369                 PyConstant_Insert( d, "LIMIT_YROT",
2370                                 PyInt_FromLong( EXPP_CONSTR_LIMYROT ) );
2371                 PyConstant_Insert( d, "LIMIT_ZROT",
2372                                 PyInt_FromLong( EXPP_CONSTR_LIMZROT ) );
2373                 
2374                 PyConstant_Insert( d, "XMIN",
2375                                 PyInt_FromLong( EXPP_CONSTR_XMIN ) );
2376                 PyConstant_Insert( d, "XMAX",
2377                                 PyInt_FromLong( EXPP_CONSTR_XMAX ) );
2378                 PyConstant_Insert( d, "YMIN",
2379                                 PyInt_FromLong( EXPP_CONSTR_YMIN ) );
2380                 PyConstant_Insert( d, "YMAX",
2381                                 PyInt_FromLong( EXPP_CONSTR_YMAX ) );
2382                 PyConstant_Insert( d, "ZMIN",
2383                                 PyInt_FromLong( EXPP_CONSTR_ZMIN ) );
2384                 PyConstant_Insert( d, "ZMAX",
2385                                 PyInt_FromLong( EXPP_CONSTR_ZMAX ) );
2386                                 
2387                 PyConstant_Insert( d, "SCRIPT",
2388                                 PyInt_FromLong( EXPP_CONSTR_SCRIPT ) );
2389                 PyConstant_Insert( d, "PROPERTIES",
2390                                 PyInt_FromLong( EXPP_CONSTR_PROPS ) );
2391                                 
2392                 PyConstant_Insert( d, "FROM",
2393                                 PyInt_FromLong( EXPP_CONSTR_FROM ) );
2394                 PyConstant_Insert( d, "TO",
2395                                 PyInt_FromLong( EXPP_CONSTR_TO ) );
2396                 PyConstant_Insert( d, "EXTRAPOLATE",
2397                                 PyInt_FromLong( EXPP_CONSTR_EXPO ) );
2398                 PyConstant_Insert( d, "MAPX",
2399                                 PyInt_FromLong( EXPP_CONSTR_MAPX ) );
2400                 PyConstant_Insert( d, "MAPY",
2401                                 PyInt_FromLong( EXPP_CONSTR_MAPY ) );
2402                 PyConstant_Insert( d, "MAPZ",
2403                                 PyInt_FromLong( EXPP_CONSTR_MAPZ ) );
2404                 PyConstant_Insert( d, "FROM_MINX",
2405                                 PyInt_FromLong( EXPP_CONSTR_FROMMINX ) );
2406                 PyConstant_Insert( d, "FROM_MAXX",
2407                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXX ) );
2408                 PyConstant_Insert( d, "FROM_MINY",
2409                                 PyInt_FromLong( EXPP_CONSTR_FROMMINY ) );
2410                 PyConstant_Insert( d, "FROM_MAXY",
2411                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXY ) );
2412                 PyConstant_Insert( d, "FROM_MINZ",
2413                                 PyInt_FromLong( EXPP_CONSTR_FROMMINZ ) );
2414                 PyConstant_Insert( d, "FROM_MAXZ",
2415                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXZ ) );
2416                 PyConstant_Insert( d, "TO_MINX",
2417                                 PyInt_FromLong( EXPP_CONSTR_TOMINX ) );
2418                 PyConstant_Insert( d, "TO_MAXX",
2419                                 PyInt_FromLong( EXPP_CONSTR_TOMAXX ) );
2420                 PyConstant_Insert( d, "TO_MINY",
2421                                 PyInt_FromLong( EXPP_CONSTR_TOMINY ) );
2422                 PyConstant_Insert( d, "TO_MAXY",
2423                                 PyInt_FromLong( EXPP_CONSTR_TOMAXY ) );
2424                 PyConstant_Insert( d, "TO_MINZ",
2425                                 PyInt_FromLong( EXPP_CONSTR_TOMINZ ) );
2426                 PyConstant_Insert( d, "TO_MAXZ",
2427                                 PyInt_FromLong( EXPP_CONSTR_TOMAXZ ) );
2428                                 
2429                 PyConstant_Insert( d, "LOC",
2430                                 PyInt_FromLong( 0 ) );
2431                 PyConstant_Insert( d, "ROT",
2432                                 PyInt_FromLong( 1 ) );
2433                 PyConstant_Insert( d, "SCALE",
2434                                 PyInt_FromLong( 2 ) );
2435                                 
2436                 PyConstant_Insert( d, "CONSTR_RB_TYPE",
2437                                 PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
2438                 PyConstant_Insert( d, "CONSTR_RB_BALL",
2439                                 PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
2440                 PyConstant_Insert( d, "CONSTR_RB_HINGE",
2441                                 PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
2442                 PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
2443                                 PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
2444                 PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
2445                                 PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
2446                 PyConstant_Insert( d, "CONSTR_RB_PIVX",
2447                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
2448                 PyConstant_Insert( d, "CONSTR_RB_PIVY",
2449                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
2450                 PyConstant_Insert( d, "CONSTR_RB_PIVZ",
2451                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
2452                 PyConstant_Insert( d, "CONSTR_RB_AXX",
2453                                 PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
2454                 PyConstant_Insert( d, "CONSTR_RB_AXY",
2455                                 PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
2456                 PyConstant_Insert( d, "CONSTR_RB_AXZ",
2457                                 PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
2458                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
2459                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
2460                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
2461                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
2462                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
2463                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
2464                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
2465                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
2466                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
2467                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
2468                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
2469                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
2470                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
2471                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
2472                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
2473                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
2474                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
2475                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
2476                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
2477                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
2478                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
2479                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
2480                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
2481                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );                           
2482                 PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
2483                                 PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
2484                 PyConstant_Insert( d, "CONSTR_RB_FLAG",
2485                                 PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
2486                                 
2487                                 
2488                 PyConstant_Insert( d, "OWNERSPACE",
2489                                 PyInt_FromLong( EXPP_CONSTR_OWNSPACE ) );
2490                 PyConstant_Insert( d, "TARGETSPACE",
2491                                 PyInt_FromLong( EXPP_CONSTR_TARSPACE ) );
2492                                 
2493                 PyConstant_Insert( d, "SPACE_WORLD",
2494                                 PyInt_FromLong( CONSTRAINT_SPACE_WORLD) );
2495                 PyConstant_Insert( d, "SPACE_LOCAL",
2496                                 PyInt_FromLong( CONSTRAINT_SPACE_LOCAL ) );
2497                 PyConstant_Insert( d, "SPACE_POSE",
2498                                 PyInt_FromLong( CONSTRAINT_SPACE_POSE) );
2499                 PyConstant_Insert( d, "SPACE_PARLOCAL",
2500                                 PyInt_FromLong( CONSTRAINT_SPACE_PARLOCAL ) );
2501         }
2502         return S;
2503 }
2504
2505 /*****************************************************************************/
2506 /* Function:              Constraint_Init                                    */
2507 /*****************************************************************************/
2508 PyObject *Constraint_Init( void )
2509 {
2510         PyObject *submodule;
2511         PyObject *TypeDict = M_Constraint_TypeDict( );
2512         PyObject *SettingsDict = M_Constraint_SettingsDict( );
2513
2514         if( PyType_Ready( &ConstraintSeq_Type ) < 0
2515                         || PyType_Ready( &Constraint_Type ) < 0 )
2516                 return NULL;
2517
2518         submodule = Py_InitModule3( "Blender.Constraint", NULL,
2519                         "Constraint module for accessing and creating constraint data" );
2520
2521         if( TypeDict )
2522                 PyModule_AddObject( submodule, "Type", TypeDict );
2523         
2524         if( SettingsDict )
2525                 PyModule_AddObject( submodule, "Settings", SettingsDict );
2526         
2527         return submodule;
2528 }