~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Lattice.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: Lattice.c 14456 2008-04-17 21:14:55Z campbellbarton $
 
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
 
26
 *
 
27
 * ***** END GPL LICENSE BLOCK *****
 
28
 */
 
29
 
 
30
#include "Lattice.h" /*This must come first*/
 
31
 
 
32
#include "BKE_utildefines.h"
 
33
#include "BKE_main.h"
 
34
#include "BKE_global.h"
 
35
#include "BKE_library.h"
 
36
#include "BKE_lattice.h"
 
37
#include "BLI_blenlib.h"
 
38
#include "DNA_object_types.h"
 
39
#include "DNA_key_types.h"
 
40
#include "DNA_mesh_types.h"
 
41
#include "DNA_meshdata_types.h"
 
42
#include "DNA_curve_types.h"
 
43
#include "DNA_scene_types.h"
 
44
#include "BIF_editkey.h"
 
45
#include "BIF_editdeform.h"
 
46
#include "BIF_space.h"
 
47
#include "blendef.h"
 
48
#include "gen_utils.h"
 
49
#include "gen_library.h"
 
50
 
 
51
#include "Key.h"
 
52
 
 
53
/*****************************************************************************/
 
54
/* Python API function prototypes for the Lattice module.       */
 
55
/*****************************************************************************/
 
56
static PyObject *M_Lattice_New( PyObject * self, PyObject * args );
 
57
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args );
 
58
 
 
59
/*****************************************************************************/
 
60
/*      Lattice Module strings   */
 
61
/* The following string definitions are used for documentation strings.  */
 
62
/* In Python these will be written to the console when doing a           */
 
63
/* Blender.Lattice.__doc__      */
 
64
/*****************************************************************************/
 
65
static char M_Lattice_doc[] = "The Blender Lattice module\n\n";
 
66
 
 
67
static char M_Lattice_New_doc[] = "() - return a new Lattice object";
 
68
 
 
69
static char M_Lattice_Get_doc[] = "() - get a Lattice from blender";
 
70
 
 
71
/*****************************************************************************/
 
72
/* Python method structure definition for Blender.Lattice module:       */
 
73
/*****************************************************************************/
 
74
struct PyMethodDef M_Lattice_methods[] = {
 
75
        {"New", ( PyCFunction ) M_Lattice_New, METH_VARARGS,
 
76
         M_Lattice_New_doc},
 
77
        {"Get", ( PyCFunction ) M_Lattice_Get, METH_VARARGS,
 
78
         M_Lattice_Get_doc},
 
79
        {NULL, NULL, 0, NULL}
 
80
};
 
81
 
 
82
 
 
83
/*****************************************************************************/
 
84
/*  Lattice Strings                      */
 
85
/* The following string definitions are used for documentation strings.  */
 
86
/* In Python these will be written to the console when doing a           */
 
87
/* Blender.Lattice.__doc__                      */
 
88
/*****************************************************************************/
 
89
static char Lattice_getName_doc[] = "() - Return Lattice Object name";
 
90
 
 
91
static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
 
92
 
 
93
static char Lattice_setPartitions_doc[] =
 
94
        "(str) - Set the number of Partitions in x,y,z";
 
95
 
 
96
static char Lattice_getPartitions_doc[] =
 
97
        "(str) - Get the number of Partitions in x,y,z";
 
98
 
 
99
static char Lattice_getKey_doc[] =
 
100
        "() - Get the Key object attached to this Lattice";
 
101
 
 
102
static char Lattice_setKeyTypes_doc[] =
 
103
        "(str) - Set the key types for x,y,z dimensions";
 
104
 
 
105
static char Lattice_getKeyTypes_doc[] =
 
106
        "(str) - Get the key types for x,y,z dimensions";
 
107
 
 
108
static char Lattice_setMode_doc[] = "(str) - Make an outside or grid lattice";
 
109
 
 
110
static char Lattice_getMode_doc[] = "(str) - Get lattice mode type";
 
111
 
 
112
static char Lattice_setPoint_doc[] =
 
113
        "(str) - Set the coordinates of a point on the lattice";
 
114
 
 
115
static char Lattice_getPoint_doc[] =
 
116
        "(str) - Get the coordinates of a point on the lattice";
 
117
 
 
118
static char Lattice_insertKey_doc[] =
 
119
        "(str) - Set a new key for the lattice at specified frame";
 
120
 
 
121
static char Lattice_copy_doc[] =
 
122
        "() - Return a copy of the lattice.";
 
123
 
 
124
//***************************************************************************
 
125
// Function:      Lattice_CreatePyObject   
 
126
//***************************************************************************
 
127
PyObject *Lattice_CreatePyObject( Lattice * lt )
 
128
{
 
129
        BPy_Lattice *pyLat;
 
130
 
 
131
        pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
 
132
 
 
133
        if( !pyLat )
 
134
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
135
                                              "couldn't create BPy_Lattice PyObject" );
 
136
 
 
137
        pyLat->lattice = lt;
 
138
 
 
139
        return ( PyObject * ) pyLat;
 
140
}
 
141
 
 
142
//***************************************************************************
 
143
// Function:       Lattice_FromPyObject     
 
144
//***************************************************************************
 
145
 
 
146
Lattice *Lattice_FromPyObject( PyObject * pyobj )
 
147
{
 
148
        return ( ( BPy_Lattice * ) pyobj )->lattice;
 
149
}
 
150
 
 
151
//***************************************************************************
 
152
// Function:       M_Lattice_New      
 
153
// Python equivalent:          Blender.Lattice.New 
 
154
//***************************************************************************
 
155
static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
 
156
{
 
157
        char *name = NULL;
 
158
        Lattice *bl_Lattice;    // blender Lattice object 
 
159
        PyObject *py_Lattice;   // python wrapper 
 
160
 
 
161
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
162
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
163
                                              "expected string and int arguments (or nothing)" );
 
164
 
 
165
        bl_Lattice = add_lattice( "Lattice" );
 
166
 
 
167
        if( bl_Lattice ) {
 
168
                bl_Lattice->id.us = 0;
 
169
                py_Lattice = Lattice_CreatePyObject( bl_Lattice );
 
170
        } else
 
171
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
172
                                              "couldn't create Lattice Object in Blender" );
 
173
        if( !py_Lattice )
 
174
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
175
                                              "couldn't create Lattice Object wrapper" );
 
176
 
 
177
        if( name )
 
178
                rename_id( &bl_Lattice->id, name );
 
179
 
 
180
        return py_Lattice;
 
181
}
 
182
 
 
183
//***************************************************************************
 
184
// Function:   M_Lattice_Get   
 
185
// Python equivalent:        Blender.Lattice.Get  
 
186
//***************************************************************************
 
187
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
 
188
{
 
189
        char *name = NULL;
 
190
        Lattice *lat_iter;
 
191
 
 
192
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
193
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
194
                                                "expected string argument (or nothing)" ) );
 
195
 
 
196
        lat_iter = G.main->latt.first;
 
197
 
 
198
        if( name ) {            /* (name) - Search Lattice by name */
 
199
 
 
200
                PyObject *wanted_lat = NULL;
 
201
 
 
202
                while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
 
203
                        if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
 
204
                                wanted_lat =
 
205
                                        Lattice_CreatePyObject( lat_iter );
 
206
                        }
 
207
 
 
208
                        lat_iter = lat_iter->id.next;
 
209
                }
 
210
 
 
211
                if( wanted_lat == NULL ) {      /* Requested Lattice doesn't exist */
 
212
                        char error_msg[64];
 
213
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
 
214
                                       "Lattice \"%s\" not found", name );
 
215
                        return ( EXPP_ReturnPyObjError
 
216
                                 ( PyExc_NameError, error_msg ) );
 
217
                }
 
218
 
 
219
                return wanted_lat;
 
220
        }
 
221
 
 
222
        else {                  /* () - return a list of all Lattices in the scene */
 
223
                int index = 0;
 
224
                PyObject *latlist, *pyobj;
 
225
 
 
226
                latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
 
227
 
 
228
                if( latlist == NULL )
 
229
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
230
                                                        "couldn't create PyList" ) );
 
231
 
 
232
                while( lat_iter ) {
 
233
                        pyobj = Lattice_CreatePyObject( lat_iter );
 
234
 
 
235
                        if( !pyobj ) {
 
236
                                Py_DECREF(latlist);
 
237
                                return ( EXPP_ReturnPyObjError
 
238
                                         ( PyExc_MemoryError,
 
239
                                           "couldn't create PyString" ) );
 
240
                        }
 
241
                        PyList_SET_ITEM( latlist, index, pyobj );
 
242
 
 
243
                        lat_iter = lat_iter->id.next;
 
244
                        index++;
 
245
                }
 
246
 
 
247
                return ( latlist );
 
248
        }
 
249
}
 
250
 
 
251
//***************************************************************************
 
252
// Function:       Lattice_Init   
 
253
//***************************************************************************
 
254
PyObject *Lattice_Init( void )
 
255
{
 
256
        PyObject *mod;
 
257
        PyObject *dict;
 
258
        
 
259
        if( PyType_Ready( &Lattice_Type ) < 0 )
 
260
                return NULL;
 
261
        
 
262
        mod = Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
 
263
                                M_Lattice_doc );
 
264
        
 
265
        dict = PyModule_GetDict( mod );
 
266
 
 
267
        //Module dictionary
 
268
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(LT_##x))
 
269
        EXPP_ADDCONST( GRID );
 
270
        EXPP_ADDCONST( OUTSIDE );
 
271
 
 
272
#undef EXPP_ADDCONST
 
273
#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(KEY_##x))
 
274
        EXPP_ADDCONST( LINEAR );
 
275
        EXPP_ADDCONST( CARDINAL );
 
276
        EXPP_ADDCONST( BSPLINE );
 
277
        
 
278
        return ( mod );
 
279
}
 
280
 
 
281
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
 
282
{
 
283
        int x = 0;
 
284
        int y = 0;
 
285
        int z = 0;
 
286
        Lattice *bl_Lattice;
 
287
 
 
288
        if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
 
289
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
290
                                                "expected int,int,int argument" ) );
 
291
 
 
292
        bl_Lattice = self->lattice;
 
293
 
 
294
        if( x < 2 || y < 2 || z < 2 )
 
295
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
296
                                                "partition values must be 2 or greater" ) );
 
297
 
 
298
        resizelattice(bl_Lattice, x, y, z, NULL);
 
299
 
 
300
        Py_RETURN_NONE;
 
301
}
 
302
 
 
303
static PyObject *Lattice_getPartitions( BPy_Lattice * self )
 
304
{
 
305
        Lattice *bl_Lattice;
 
306
        bl_Lattice = self->lattice;
 
307
 
 
308
        return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
 
309
                              ( int ) bl_Lattice->pntsv,
 
310
                              ( int ) bl_Lattice->pntsw );
 
311
}
 
312
 
 
313
static PyObject *Lattice_getKey( BPy_Lattice * self )
 
314
{
 
315
        Key *key = self->lattice->key;
 
316
 
 
317
        if (key)
 
318
                return Key_CreatePyObject(key);
 
319
        else
 
320
                Py_RETURN_NONE;
 
321
}
 
322
 
 
323
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self )
 
324
{
 
325
        Lattice *bl_Lattice;
 
326
        char *linear = "linear";
 
327
        char *cardinal = "cardinal";
 
328
        char *bspline = "bspline";
 
329
        char *s_x = NULL, *s_y = NULL, *s_z = NULL;
 
330
 
 
331
        bl_Lattice = self->lattice;
 
332
 
 
333
        if( ( bl_Lattice->typeu ) == KEY_LINEAR )
 
334
                s_x = linear;
 
335
        else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
 
336
                s_x = cardinal;
 
337
        else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
 
338
                s_x = bspline;
 
339
        else
 
340
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
341
                                              "bad key type..." );
 
342
 
 
343
        if( ( bl_Lattice->typev ) == KEY_LINEAR )
 
344
                s_y = linear;
 
345
        else if( ( bl_Lattice->typev ) == KEY_CARDINAL )
 
346
                s_y = cardinal;
 
347
        else if( ( bl_Lattice->typev ) == KEY_BSPLINE )
 
348
                s_y = bspline;
 
349
        else
 
350
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
351
                                              "bad key type..." );
 
352
 
 
353
        if( ( bl_Lattice->typew ) == KEY_LINEAR )
 
354
                s_z = linear;
 
355
        else if( ( bl_Lattice->typew ) == KEY_CARDINAL )
 
356
                s_z = cardinal;
 
357
        else if( ( bl_Lattice->typew ) == KEY_BSPLINE )
 
358
                s_z = bspline;
 
359
        else
 
360
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
361
                                              "bad key type..." );
 
362
 
 
363
        /* we made sure no s_[xyz] is NULL */
 
364
        return Py_BuildValue( "[s,s,s]", s_x, s_y, s_z );
 
365
}
 
366
 
 
367
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args )
 
368
{
 
369
        int x;
 
370
        int y;
 
371
        int z;
 
372
        Lattice *bl_Lattice;
 
373
 
 
374
        if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
 
375
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
376
                                                "expected int,int,int argument" ) );
 
377
 
 
378
        bl_Lattice = self->lattice;
 
379
 
 
380
        if( x == KEY_LINEAR )
 
381
                bl_Lattice->typeu = KEY_LINEAR;
 
382
        else if( x == KEY_CARDINAL )
 
383
                bl_Lattice->typeu = KEY_CARDINAL;
 
384
        else if( x == KEY_BSPLINE )
 
385
                bl_Lattice->typeu = KEY_BSPLINE;
 
386
        else
 
387
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
388
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
 
389
 
 
390
        if( y == KEY_LINEAR )
 
391
                bl_Lattice->typev = KEY_LINEAR;
 
392
        else if( y == KEY_CARDINAL )
 
393
                bl_Lattice->typev = KEY_CARDINAL;
 
394
        else if( y == KEY_BSPLINE )
 
395
                bl_Lattice->typev = KEY_BSPLINE;
 
396
        else
 
397
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
398
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
 
399
 
 
400
        if( z == KEY_LINEAR )
 
401
                bl_Lattice->typew = KEY_LINEAR;
 
402
        else if( z == KEY_CARDINAL )
 
403
                bl_Lattice->typew = KEY_CARDINAL;
 
404
        else if( z == KEY_BSPLINE )
 
405
                bl_Lattice->typew = KEY_BSPLINE;
 
406
        else
 
407
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
408
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
 
409
 
 
410
        Py_RETURN_NONE;
 
411
}
 
412
 
 
413
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args )
 
414
{
 
415
        short type;
 
416
        Lattice *bl_Lattice;
 
417
        bl_Lattice = self->lattice;
 
418
 
 
419
        if( !PyArg_ParseTuple( args, "h", &type ) )
 
420
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
421
                                                "expected int argument" ) );
 
422
 
 
423
        if( type == LT_GRID )
 
424
                bl_Lattice->flag = LT_GRID;
 
425
        else if( type == LT_OUTSIDE ) {
 
426
                bl_Lattice->flag = LT_OUTSIDE + LT_GRID;
 
427
                outside_lattice( bl_Lattice );
 
428
        } else
 
429
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
430
                                              "type must be either GRID or OUTSIDE" );
 
431
 
 
432
        Py_RETURN_NONE;
 
433
}
 
434
 
 
435
static PyObject *Lattice_getMode(BPy_Lattice * self)
 
436
{
 
437
        if( self->lattice->flag == 1 )
 
438
                return PyString_FromString( "Grid" );
 
439
        else if( self->lattice->flag == 3 )
 
440
                return PyString_FromString( "Outside" );
 
441
        Py_RETURN_NONE;
 
442
}
 
443
 
 
444
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args )
 
445
{
 
446
        BPoint *bp, *bpoint;
 
447
        short size;
 
448
        Lattice *bl_Lattice;
 
449
        int index, x;
 
450
        float tempInt;
 
451
        PyObject *listObject;
 
452
 
 
453
        if( !PyArg_ParseTuple
 
454
            ( args, "iO!", &index, &PyList_Type, &listObject ) )
 
455
                return ( EXPP_ReturnPyObjError
 
456
                         ( PyExc_TypeError, "expected int & list argument" ) );
 
457
 
 
458
        if( !PyList_Check( listObject ) )
 
459
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
460
                                                "2nd parameter should be a python list" ) );
 
461
 
 
462
        if( !( PyList_Size( listObject ) == 3 ) )
 
463
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
464
                                                "Please pass 3 parameters in the list [x,y,z]" ) );
 
465
 
 
466
        //init
 
467
        bp = 0;
 
468
        bl_Lattice = self->lattice;
 
469
 
 
470
        //get bpoints
 
471
        bp = bl_Lattice->def;
 
472
 
 
473
        if( bp == 0 )
 
474
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
475
                                                "no lattice points!" ) );
 
476
 
 
477
        //calculate size of lattice
 
478
        size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
 
479
 
 
480
        if( index < 0 || index > size )
 
481
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
482
                                                "index outside of lattice size!" ) );
 
483
 
 
484
        //get the bpoint
 
485
        while( index ) {
 
486
                index--;
 
487
                bp++;
 
488
        }
 
489
        bpoint = bp;
 
490
 
 
491
        for( x = 0; x < PyList_Size( listObject ); x++ ) {
 
492
                if( !
 
493
                    ( PyArg_Parse
 
494
                      ( ( PyList_GetItem( listObject, x ) ), "f",
 
495
                        &tempInt ) ) )
 
496
                        return EXPP_ReturnPyObjError( PyExc_TypeError,
 
497
                                                      "python list integer not parseable" );
 
498
                bpoint->vec[x] = tempInt;
 
499
        }
 
500
 
 
501
        Py_RETURN_NONE;
 
502
}
 
503
 
 
504
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
 
505
{
 
506
        BPoint *bp, *bpoint;
 
507
        short size;
 
508
        Lattice *bl_Lattice;
 
509
        int index;
 
510
 
 
511
        if( !PyArg_ParseTuple( args, "i", &index ) )
 
512
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
513
                                                "expected int argument" ) );
 
514
 
 
515
        //init
 
516
        bp = 0;
 
517
        bl_Lattice = self->lattice;
 
518
 
 
519
        //get bpoints
 
520
        bp = bl_Lattice->def;
 
521
 
 
522
        if( bp == 0 )
 
523
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
524
                                                "no lattice points!" ) );
 
525
 
 
526
        //calculate size of lattice
 
527
        size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
 
528
 
 
529
        if( index < 0 || index > size )
 
530
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
531
                                                "index outside of lattice size!" ) );
 
532
 
 
533
        //get the bpoint
 
534
        while( index ) {
 
535
                index--;
 
536
                bp++;
 
537
        }
 
538
        bpoint = bp;
 
539
 
 
540
        if( bpoint == 0 )
 
541
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
542
                                                "bpoint does not exist" ) );
 
543
 
 
544
        return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
 
545
}
 
546
 
 
547
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
 
548
{
 
549
        Lattice *lt;
 
550
        int frame = -1, oldfra = -1;
 
551
 
 
552
        if( !PyArg_ParseTuple( args, "i", &frame ) )
 
553
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
554
                                                "expected int argument" ) );
 
555
 
 
556
        lt = self->lattice;
 
557
 
 
558
        //set the current frame
 
559
        if( frame > 0 ) {
 
560
                frame = EXPP_ClampInt( frame, 1, MAXFRAME );
 
561
                oldfra = G.scene->r.cfra;
 
562
                G.scene->r.cfra = (int)frame;
 
563
        }
 
564
//      else just use current frame, then
 
565
//              return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
 
566
//                                              "frame value has to be greater than 0"));
 
567
 
 
568
        //insert a keybock for the lattice (1=relative)
 
569
        insert_lattkey( lt , 1);
 
570
        allspace(REMAKEIPO, 0);
 
571
 
 
572
        if( frame > 0 )
 
573
                G.scene->r.cfra = (int)oldfra;
 
574
 
 
575
        Py_RETURN_NONE;
 
576
}
 
577
 
 
578
static PyObject *Lattice_copy( BPy_Lattice * self )
 
579
{
 
580
        Lattice *bl_Lattice;    // blender Lattice object 
 
581
        PyObject *py_Lattice;   // python wrapper 
 
582
 
 
583
        bl_Lattice = copy_lattice( self->lattice );
 
584
        bl_Lattice->id.us = 0;
 
585
 
 
586
        if( bl_Lattice )
 
587
                py_Lattice = Lattice_CreatePyObject( bl_Lattice );
 
588
        else
 
589
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
590
                                              "couldn't create Lattice Object in Blender" );
 
591
        if( !py_Lattice )
 
592
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
593
                                              "couldn't create Lattice Object wrapper" );
 
594
 
 
595
        return py_Lattice;
 
596
}
 
597
 
 
598
static int Lattice_compare( BPy_Lattice * a, BPy_Lattice * b )
 
599
{
 
600
        return ( a->lattice == b->lattice ) ? 0 : -1;
 
601
}
 
602
 
 
603
 
 
604
//***************************************************************************
 
605
// Function:  Lattice_repr   
 
606
// Description: This is a callback function for the BPy_Lattice type. It 
 
607
//                  builds a meaninful string to represent Lattice objects. 
 
608
//***************************************************************************
 
609
static PyObject *Lattice_repr( BPy_Lattice * self )
 
610
{
 
611
        if( self->lattice )
 
612
                return PyString_FromFormat( "[Lattice \"%s\"]",
 
613
                                            self->lattice->id.name + 2 );
 
614
        else
 
615
                return PyString_FromString( "[Lattice <deleted>]" );
 
616
}
 
617
 
 
618
/*****************************************************************************/
 
619
/* Python BPy_Lattice methods table:    */
 
620
/*****************************************************************************/
 
621
static PyMethodDef BPy_Lattice_methods[] = {
 
622
        /* name, method, flags, doc */
 
623
        {"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
 
624
         Lattice_getName_doc},
 
625
        {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
 
626
         Lattice_setName_doc},
 
627
        {"setPartitions", ( PyCFunction ) Lattice_setPartitions, METH_VARARGS,
 
628
         Lattice_setPartitions_doc},
 
629
        {"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS,
 
630
         Lattice_getPartitions_doc},
 
631
        {"getKey", ( PyCFunction ) Lattice_getKey, METH_NOARGS,
 
632
         Lattice_getKey_doc},
 
633
        {"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS,
 
634
         Lattice_setKeyTypes_doc},
 
635
        {"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS,
 
636
         Lattice_getKeyTypes_doc},
 
637
        {"setMode", ( PyCFunction ) Lattice_setMode, METH_VARARGS,
 
638
         Lattice_setMode_doc},
 
639
        {"getMode", ( PyCFunction ) Lattice_getMode, METH_NOARGS,
 
640
         Lattice_getMode_doc},
 
641
        {"setPoint", ( PyCFunction ) Lattice_setPoint, METH_VARARGS,
 
642
         Lattice_setPoint_doc},
 
643
        {"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
 
644
         Lattice_getPoint_doc},
 
645
        {"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
 
646
         Lattice_insertKey_doc},
 
647
        {"__copy__", ( PyCFunction ) Lattice_copy, METH_NOARGS,
 
648
         Lattice_copy_doc},
 
649
        {"copy", ( PyCFunction ) Lattice_copy, METH_NOARGS,
 
650
         Lattice_copy_doc},
 
651
        {NULL, NULL, 0, NULL}
 
652
};
 
653
 
 
654
/*****************************************************************************/
 
655
/* Python attributes get/set functions:                                      */
 
656
/*****************************************************************************/
 
657
static PyObject *Lattice_getWidth(BPy_Lattice * self)
 
658
{
 
659
        return PyInt_FromLong( self->lattice->pntsu );
 
660
}
 
661
static PyObject *Lattice_getHeight(BPy_Lattice * self)
 
662
{
 
663
        return PyInt_FromLong( self->lattice->pntsv );
 
664
}
 
665
static PyObject *Lattice_getDepth(BPy_Lattice * self)
 
666
{
 
667
        return PyInt_FromLong( self->lattice->pntsw );
 
668
}
 
669
static PyObject *Lattice_getLatSize(BPy_Lattice * self)
 
670
{
 
671
        return PyInt_FromLong(
 
672
                self->lattice->pntsu * self->lattice->pntsv * self->lattice->pntsw );
 
673
}
 
674
 
 
675
 
 
676
static PyObject *Lattice_getAxisType(BPy_Lattice * self, void * type)
 
677
{
 
678
        char interp_type = 0;
 
679
        switch ( GET_INT_FROM_POINTER(type) ) {
 
680
        case 0:
 
681
                interp_type = self->lattice->typeu;
 
682
                break;
 
683
        case 1:
 
684
                interp_type = self->lattice->typev;
 
685
                break;
 
686
        case 2:
 
687
                interp_type = self->lattice->typew;
 
688
                break;
 
689
        }
 
690
        
 
691
        switch (interp_type) {
 
692
        case 0:
 
693
                return PyString_FromString( "Linear" );
 
694
        case 1:
 
695
                return PyString_FromString( "Cardinal" );
 
696
        case 2:
 
697
                return PyString_FromString( "Bspline" );
 
698
        }
 
699
        Py_RETURN_NONE;
 
700
}
 
701
 
 
702
/*****************************************************************************/
 
703
/* Python attributes get/set structure:                                      */
 
704
/*****************************************************************************/
 
705
static PyGetSetDef BPy_Lattice_getseters[] = {
 
706
        GENERIC_LIB_GETSETATTR,
 
707
        {"width", (getter)Lattice_getWidth, (setter)NULL,
 
708
         "lattice U subdivision ", NULL},
 
709
        {"height", (getter)Lattice_getHeight, (setter)NULL,
 
710
         "lattice V subdivision", NULL},
 
711
        {"depth", (getter)Lattice_getDepth, (setter)NULL,
 
712
         "lattice W subdivision", NULL},
 
713
        {"latSize", (getter)Lattice_getLatSize, (setter)NULL,
 
714
         "lattice W subdivision", NULL},         
 
715
         
 
716
        {"widthType", (getter)Lattice_getAxisType, NULL,
 
717
         "lattice U interpolation type", (void *)0},
 
718
        {"heightType", (getter)Lattice_getAxisType, NULL,
 
719
         "lattice V interpolation type", (void *)1},
 
720
        {"depthType", (getter)Lattice_getAxisType, NULL,
 
721
         "lattice W interpolation type", (void *)2},
 
722
 
 
723
        {"key", (getter)Lattice_getKey, NULL,
 
724
         "lattice key", NULL},
 
725
        {"mode", (getter)Lattice_getMode, NULL,
 
726
         "lattice key", NULL},
 
727
         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
728
};
 
729
 
 
730
/*****************************************************************************/
 
731
/* Python Lattice_Type structure definition:            */
 
732
/*****************************************************************************/
 
733
PyTypeObject Lattice_Type = {
 
734
        PyObject_HEAD_INIT( NULL ) 
 
735
        0,      /* ob_size */
 
736
        "Blender Lattice",      /* tp_name */
 
737
        sizeof( BPy_Lattice ),  /* tp_basicsize */
 
738
        0,                      /* tp_itemsize */
 
739
        /* methods */
 
740
        NULL,   /* tp_dealloc */
 
741
        0,              /* tp_print */
 
742
        NULL,   /* tp_getattr */
 
743
        NULL,   /* tp_setattr */
 
744
        ( cmpfunc ) Lattice_compare,                    /* tp_compare */
 
745
        ( reprfunc ) Lattice_repr,      /* tp_repr */
 
746
 
 
747
        /* Method suites for standard classes */
 
748
 
 
749
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
750
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
751
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
752
 
 
753
        /* More standard operations (here for binary compatibility) */
 
754
 
 
755
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
 
756
        NULL,                       /* ternaryfunc tp_call; */
 
757
        NULL,                       /* reprfunc tp_str; */
 
758
        NULL,                       /* getattrofunc tp_getattro; */
 
759
        NULL,                       /* setattrofunc tp_setattro; */
 
760
 
 
761
        /* Functions to access object as input/output buffer */
 
762
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
763
 
 
764
  /*** Flags to define presence of optional/expanded features ***/
 
765
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
766
 
 
767
        NULL,                       /*  char *tp_doc;  Documentation string */
 
768
  /*** Assigned meaning in release 2.0 ***/
 
769
        /* call function for all accessible objects */
 
770
        NULL,                       /* traverseproc tp_traverse; */
 
771
 
 
772
        /* delete references to contained objects */
 
773
        NULL,                       /* inquiry tp_clear; */
 
774
 
 
775
  /***  Assigned meaning in release 2.1 ***/
 
776
  /*** rich comparisons ***/
 
777
        NULL,                       /* richcmpfunc tp_richcompare; */
 
778
 
 
779
  /***  weak reference enabler ***/
 
780
        0,                          /* long tp_weaklistoffset; */
 
781
 
 
782
  /*** Added in release 2.2 ***/
 
783
        /*   Iterators */
 
784
        NULL,                       /* getiterfunc tp_iter; */
 
785
        NULL,                       /* iternextfunc tp_iternext; */
 
786
 
 
787
  /*** Attribute descriptor and subclassing stuff ***/
 
788
        BPy_Lattice_methods,           /* struct PyMethodDef *tp_methods; */
 
789
        NULL,                       /* struct PyMemberDef *tp_members; */
 
790
        BPy_Lattice_getseters,         /* struct PyGetSetDef *tp_getset; */
 
791
        NULL,                       /* struct _typeobject *tp_base; */
 
792
        NULL,                       /* PyObject *tp_dict; */
 
793
        NULL,                       /* descrgetfunc tp_descr_get; */
 
794
        NULL,                       /* descrsetfunc tp_descr_set; */
 
795
        0,                          /* long tp_dictoffset; */
 
796
        NULL,                       /* initproc tp_init; */
 
797
        NULL,                       /* allocfunc tp_alloc; */
 
798
        NULL,                       /* newfunc tp_new; */
 
799
        /*  Low-level free-memory routine */
 
800
        NULL,                       /* freefunc tp_free;  */
 
801
        /* For PyObject_IS_GC */
 
802
        NULL,                       /* inquiry tp_is_gc;  */
 
803
        NULL,                       /* PyObject *tp_bases; */
 
804
        /* method resolution order */
 
805
        NULL,                       /* PyObject *tp_mro;  */
 
806
        NULL,                       /* PyObject *tp_cache; */
 
807
        NULL,                       /* PyObject *tp_subclasses; */
 
808
        NULL,                       /* PyObject *tp_weaklist; */
 
809
        NULL
 
810
};