~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Constraint.c

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

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