~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
 
2
 * $Id: Lattice.c,v 1.10 2005/05/22 07:22:33 ianwill Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
31
32
 
32
33
#include "Lattice.h"
33
34
 
34
 
//***************************************************************************
35
 
// Function:                                                    Lattice_CreatePyObject                                                                                                                          
36
 
//***************************************************************************
37
 
PyObject *Lattice_CreatePyObject (Lattice *lt)
 
35
 
 
36
#include <BKE_main.h>
 
37
#include <BKE_global.h>
 
38
#include <BKE_library.h>
 
39
#include <BKE_lattice.h>
 
40
#include <BKE_utildefines.h>
 
41
#include <BKE_key.h>
 
42
#include <BLI_blenlib.h>
 
43
 
 
44
#include <DNA_key_types.h>
 
45
#include <DNA_curve_types.h>
 
46
#include <DNA_scene_types.h>
 
47
#include <BIF_editlattice.h>
 
48
#include <BIF_editkey.h>
 
49
#include "blendef.h"
 
50
#include "mydevice.h"
 
51
#include "constant.h"
 
52
#include "gen_utils.h"
 
53
 
 
54
 
 
55
/*****************************************************************************/
 
56
/* Python API function prototypes for the Lattice module.       */
 
57
/*****************************************************************************/
 
58
static PyObject *M_Lattice_New( PyObject * self, PyObject * args );
 
59
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args );
 
60
 
 
61
/*****************************************************************************/
 
62
/*      Lattice Module strings   */
 
63
/* The following string definitions are used for documentation strings.  */
 
64
/* In Python these will be written to the console when doing a           */
 
65
/* Blender.Lattice.__doc__      */
 
66
/*****************************************************************************/
 
67
static char M_Lattice_doc[] = "The Blender Lattice module\n\n";
 
68
 
 
69
static char M_Lattice_New_doc[] = "() - return a new Lattice object";
 
70
 
 
71
static char M_Lattice_Get_doc[] = "() - geta a Lattice from blender";
 
72
 
 
73
/*****************************************************************************/
 
74
/* Python method structure definition for Blender.Lattice module:       */
 
75
/*****************************************************************************/
 
76
struct PyMethodDef M_Lattice_methods[] = {
 
77
        {"New", ( PyCFunction ) M_Lattice_New, METH_VARARGS,
 
78
         M_Lattice_New_doc},
 
79
        {"Get", ( PyCFunction ) M_Lattice_Get, METH_VARARGS,
 
80
         M_Lattice_Get_doc},
 
81
        {NULL, NULL, 0, NULL}
 
82
};
 
83
 
 
84
 
 
85
 
 
86
/*****************************************************************************/
 
87
/* Python BPy_Lattice methods declarations:     */
 
88
/*****************************************************************************/
 
89
static PyObject *Lattice_getName( BPy_Lattice * self );
 
90
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args );
 
91
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args );
 
92
static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args );
 
93
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args );
 
94
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args );
 
95
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args );
 
96
static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args );
 
97
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args );
 
98
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args );
 
99
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args );
 
100
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args );
 
101
 
 
102
/*****************************************************************************/
 
103
/*  Lattice Strings                      */
 
104
/* The following string definitions are used for documentation strings.  */
 
105
/* In Python these will be written to the console when doing a           */
 
106
/* Blender.Lattice.__doc__                      */
 
107
/*****************************************************************************/
 
108
static char Lattice_getName_doc[] = "() - Return Lattice Object name";
 
109
 
 
110
static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
 
111
 
 
112
static char Lattice_setPartitions_doc[] =
 
113
        "(str) - Set the number of Partitions in x,y,z";
 
114
 
 
115
static char Lattice_getPartitions_doc[] =
 
116
        "(str) - Get the number of Partitions in x,y,z";
 
117
 
 
118
static char Lattice_setKeyTypes_doc[] =
 
119
        "(str) - Set the key types for x,y,z dimensions";
 
120
 
 
121
static char Lattice_getKeyTypes_doc[] =
 
122
        "(str) - Get the key types for x,y,z dimensions";
 
123
 
 
124
static char Lattice_setMode_doc[] = "(str) - Make an outside or grid lattice";
 
125
 
 
126
static char Lattice_getMode_doc[] = "(str) - Get lattice mode type";
 
127
 
 
128
static char Lattice_setPoint_doc[] =
 
129
        "(str) - Set the coordinates of a point on the lattice";
 
130
 
 
131
static char Lattice_getPoint_doc[] =
 
132
        "(str) - Get the coordinates of a point on the lattice";
 
133
 
 
134
static char Lattice_applyDeform_doc[] =
 
135
        "(force = False) - Apply the new lattice deformation to children\n\n\
 
136
(force = False) - if given and True, children of mesh type are not ignored.\n\
 
137
Meshes are treated differently in Blender, deformation is stored directly in\n\
 
138
their vertices when first redrawn (ex: with Blender.Redraw) after getting a\n\
 
139
Lattice parent, without needing this method (except for command line bg\n\
 
140
mode). If forced, the deformation will be applied over any previous one(s).";
 
141
 
 
142
static char Lattice_insertKey_doc[] =
 
143
        "(str) - Set a new key for the lattice at specified frame";
 
144
 
 
145
/*****************************************************************************/
 
146
/* Python BPy_Lattice methods table:    */
 
147
/*****************************************************************************/
 
148
static PyMethodDef BPy_Lattice_methods[] = {
 
149
        /* name, method, flags, doc */
 
150
        {"getName", ( PyCFunction ) Lattice_getName, METH_NOARGS,
 
151
         Lattice_getName_doc},
 
152
        {"setName", ( PyCFunction ) Lattice_setName, METH_VARARGS,
 
153
         Lattice_setName_doc},
 
154
        {"setPartitions", ( PyCFunction ) Lattice_setPartitions, METH_VARARGS,
 
155
         Lattice_setPartitions_doc},
 
156
        {"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS,
 
157
         Lattice_getPartitions_doc},
 
158
        {"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS,
 
159
         Lattice_setKeyTypes_doc},
 
160
        {"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS,
 
161
         Lattice_getKeyTypes_doc},
 
162
        {"setMode", ( PyCFunction ) Lattice_setMode, METH_VARARGS,
 
163
         Lattice_setMode_doc},
 
164
        {"getMode", ( PyCFunction ) Lattice_getMode, METH_NOARGS,
 
165
         Lattice_getMode_doc},
 
166
        {"setPoint", ( PyCFunction ) Lattice_setPoint, METH_VARARGS,
 
167
         Lattice_setPoint_doc},
 
168
        {"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
 
169
         Lattice_getPoint_doc},
 
170
        {"applyDeform", ( PyCFunction ) Lattice_applyDeform, METH_VARARGS,
 
171
         Lattice_applyDeform_doc},
 
172
        {"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
 
173
         Lattice_insertKey_doc},
 
174
        {NULL, NULL, 0, NULL}
 
175
};
 
176
 
 
177
/*****************************************************************************/
 
178
/* Python Lattice_Type callback function prototypes:    */
 
179
/*****************************************************************************/
 
180
static void Lattice_dealloc( BPy_Lattice * self );
 
181
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * v );
 
182
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name );
 
183
static PyObject *Lattice_repr( BPy_Lattice * self );
 
184
 
 
185
/*****************************************************************************/
 
186
/* Python Lattice_Type structure definition:            */
 
187
/*****************************************************************************/
 
188
PyTypeObject Lattice_Type = {
 
189
        PyObject_HEAD_INIT( NULL ) 
 
190
        0,      /* ob_size */
 
191
        "Blender Lattice",      /* tp_name */
 
192
        sizeof( BPy_Lattice ),  /* tp_basicsize */
 
193
        0,                      /* tp_itemsize */
 
194
        /* methods */
 
195
        ( destructor ) Lattice_dealloc, /* tp_dealloc */
 
196
        0,                      /* tp_print */
 
197
        ( getattrfunc ) Lattice_getAttr,        /* tp_getattr */
 
198
        ( setattrfunc ) Lattice_setAttr,        /* tp_setattr */
 
199
        0,                      /* tp_compare */
 
200
        ( reprfunc ) Lattice_repr,      /* tp_repr */
 
201
        0,                      /* tp_as_number */
 
202
        0,                      /* tp_as_sequence */
 
203
        0,                      /* tp_as_mapping */
 
204
        0,                      /* tp_as_hash */
 
205
        0, 0, 0, 0, 0, 0,
 
206
        0,                      /* tp_doc */
 
207
        0, 0, 0, 0, 0, 0,
 
208
        BPy_Lattice_methods,    /* tp_methods */
 
209
        0,                      /* tp_members */
 
210
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
211
};
 
212
 
 
213
static int Lattice_InLatList( BPy_Lattice * self );
 
214
static int Lattice_IsLinkedToObject( BPy_Lattice * self );
 
215
 
 
216
 
 
217
//***************************************************************************
 
218
// Function:      Lattice_CreatePyObject   
 
219
//***************************************************************************
 
220
PyObject *Lattice_CreatePyObject( Lattice * lt )
38
221
{
39
222
        BPy_Lattice *pyLat;
40
223
 
41
 
        pyLat = (BPy_Lattice *)PyObject_NEW (BPy_Lattice, &Lattice_Type);
 
224
        pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
42
225
 
43
 
        if (!pyLat)
44
 
                return EXPP_ReturnPyObjError (PyExc_MemoryError,
45
 
                                                 "couldn't create BPy_Lattice PyObject");
 
226
        if( !pyLat )
 
227
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
228
                                              "couldn't create BPy_Lattice PyObject" );
46
229
 
47
230
        pyLat->Lattice = lt;
48
231
 
49
 
        return (PyObject *)pyLat;
50
 
}
51
 
 
52
 
//***************************************************************************
53
 
// Function:                                                    Lattice_FromPyObject                                                                                                                            
54
 
//***************************************************************************
55
 
 
56
 
Lattice *Lattice_FromPyObject (PyObject *pyobj)
57
 
{
58
 
                return ((BPy_Lattice *)pyobj)->Lattice;
59
 
}
60
 
 
61
 
//***************************************************************************
62
 
// Function:                                                    Lattice_CheckPyObject                                                                                                                            
63
 
//***************************************************************************
64
 
int Lattice_CheckPyObject (PyObject *pyobj)
65
 
{
66
 
        return (pyobj->ob_type == &Lattice_Type);
67
 
}
68
 
        
69
 
//***************************************************************************
70
 
// Function:                                                    M_Lattice_New                                                                                                                                                                   
71
 
// Python equivalent:                   Blender.Lattice.New                                                                                                                                             
72
 
//***************************************************************************
73
 
static PyObject *M_Lattice_New(PyObject *self, PyObject *args)
 
232
        return ( PyObject * ) pyLat;
 
233
}
 
234
 
 
235
//***************************************************************************
 
236
// Function:       Lattice_FromPyObject     
 
237
//***************************************************************************
 
238
 
 
239
Lattice *Lattice_FromPyObject( PyObject * pyobj )
 
240
{
 
241
        return ( ( BPy_Lattice * ) pyobj )->Lattice;
 
242
}
 
243
 
 
244
//***************************************************************************
 
245
// Function:    Lattice_CheckPyObject     
 
246
//***************************************************************************
 
247
int Lattice_CheckPyObject( PyObject * pyobj )
 
248
{
 
249
        return ( pyobj->ob_type == &Lattice_Type );
 
250
}
 
251
 
 
252
//***************************************************************************
 
253
// Function:       M_Lattice_New      
 
254
// Python equivalent:          Blender.Lattice.New 
 
255
//***************************************************************************
 
256
static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
74
257
{
75
258
        char *name = NULL;
76
259
        char buf[21];
77
 
        Lattice  * bl_Lattice; // blender Lattice object 
78
 
        PyObject * py_Lattice; // python wrapper 
79
 
 
80
 
        if (!PyArg_ParseTuple(args, "|s", &name))
81
 
                                return EXPP_ReturnPyObjError (PyExc_AttributeError,
82
 
                                        "expected string and int arguments (or nothing)");
83
 
 
84
 
        bl_Lattice = add_lattice();
 
260
        Lattice *bl_Lattice;    // blender Lattice object 
 
261
        PyObject *py_Lattice;   // python wrapper 
 
262
 
 
263
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
264
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
265
                                              "expected string and int arguments (or nothing)" );
 
266
 
 
267
        bl_Lattice = add_lattice(  );
85
268
        bl_Lattice->id.us = 0;
86
269
 
87
 
        if (bl_Lattice)
88
 
                py_Lattice = Lattice_CreatePyObject (bl_Lattice);
 
270
        if( bl_Lattice )
 
271
                py_Lattice = Lattice_CreatePyObject( bl_Lattice );
89
272
        else
90
 
                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
91
 
                                                                                "couldn't create Lattice Object in Blender");
92
 
        if (!py_Lattice)
93
 
                return EXPP_ReturnPyObjError (PyExc_MemoryError,
94
 
                                                                                "couldn't create Lattice Object wrapper");
 
273
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
274
                                              "couldn't create Lattice Object in Blender" );
 
275
        if( !py_Lattice )
 
276
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
277
                                              "couldn't create Lattice Object wrapper" );
95
278
 
96
 
        if (name) {
97
 
                PyOS_snprintf(buf, sizeof(buf), "%s", name);
98
 
                rename_id(&bl_Lattice->id, buf);
 
279
        if( name ) {
 
280
                PyOS_snprintf( buf, sizeof( buf ), "%s", name );
 
281
                rename_id( &bl_Lattice->id, buf );
99
282
        }
100
283
 
101
284
        return py_Lattice;
102
285
}
103
286
 
104
287
//***************************************************************************
105
 
// Function:                                                    M_Lattice_Get                                                                                                                                                                   
106
 
// Python equivalent:                   Blender.Lattice.Get                                                                                                                                     
 
288
// Function:   M_Lattice_Get   
 
289
// Python equivalent:        Blender.Lattice.Get  
107
290
//***************************************************************************
108
 
static PyObject *M_Lattice_Get(PyObject *self, PyObject *args)
 
291
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
109
292
{
110
 
  char *name = NULL;
111
 
  Lattice *lat_iter;
112
 
 
113
 
  if (!PyArg_ParseTuple(args, "|s", &name))
114
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
115
 
            "expected string argument (or nothing)"));
116
 
 
117
 
  lat_iter = G.main->latt.first;
118
 
 
119
 
  if (name) { /* (name) - Search Lattice by name */
120
 
 
121
 
    PyObject *wanted_lat = NULL;
122
 
 
123
 
    while ((lat_iter) && (wanted_lat == NULL)) {
124
 
      if (strcmp (name, lat_iter->id.name+2) == 0) {
125
 
        wanted_lat = Lattice_CreatePyObject (lat_iter);
126
 
      }
127
 
 
128
 
      lat_iter = lat_iter->id.next;
129
 
    }
130
 
 
131
 
    if (wanted_lat == NULL) { /* Requested Lattice doesn't exist */
132
 
      char error_msg[64];
133
 
      PyOS_snprintf(error_msg, sizeof(error_msg),
134
 
                      "Lattice \"%s\" not found", name);
135
 
      return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
136
 
    }
137
 
 
138
 
    return wanted_lat;
139
 
  }
140
 
 
141
 
  else { /* () - return a list of all Lattices in the scene */
142
 
    int index = 0;
143
 
    PyObject *latlist, *pyobj;
144
 
 
145
 
    latlist = PyList_New (BLI_countlist (&(G.main->latt)));
146
 
 
147
 
    if (latlist == NULL)
148
 
      return (EXPP_ReturnPyObjError (PyExc_MemoryError,
149
 
              "couldn't create PyList"));
150
 
 
151
 
    while (lat_iter) {
152
 
      pyobj = Lattice_CreatePyObject(lat_iter);
153
 
 
154
 
      if (!pyobj)
155
 
        return (EXPP_ReturnPyObjError (PyExc_MemoryError,
156
 
                   "couldn't create PyString"));
157
 
 
158
 
      PyList_SET_ITEM (latlist, index, pyobj);
159
 
 
160
 
      lat_iter = lat_iter->id.next;
161
 
      index++;
162
 
    }
163
 
 
164
 
    return (latlist);
165
 
  }
 
293
        char *name = NULL;
 
294
        Lattice *lat_iter;
 
295
 
 
296
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
297
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
298
                                                "expected string argument (or nothing)" ) );
 
299
 
 
300
        lat_iter = G.main->latt.first;
 
301
 
 
302
        if( name ) {            /* (name) - Search Lattice by name */
 
303
 
 
304
                PyObject *wanted_lat = NULL;
 
305
 
 
306
                while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
 
307
                        if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
 
308
                                wanted_lat =
 
309
                                        Lattice_CreatePyObject( lat_iter );
 
310
                        }
 
311
 
 
312
                        lat_iter = lat_iter->id.next;
 
313
                }
 
314
 
 
315
                if( wanted_lat == NULL ) {      /* Requested Lattice doesn't exist */
 
316
                        char error_msg[64];
 
317
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
 
318
                                       "Lattice \"%s\" not found", name );
 
319
                        return ( EXPP_ReturnPyObjError
 
320
                                 ( PyExc_NameError, error_msg ) );
 
321
                }
 
322
 
 
323
                return wanted_lat;
 
324
        }
 
325
 
 
326
        else {                  /* () - return a list of all Lattices in the scene */
 
327
                int index = 0;
 
328
                PyObject *latlist, *pyobj;
 
329
 
 
330
                latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
 
331
 
 
332
                if( latlist == NULL )
 
333
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
334
                                                        "couldn't create PyList" ) );
 
335
 
 
336
                while( lat_iter ) {
 
337
                        pyobj = Lattice_CreatePyObject( lat_iter );
 
338
 
 
339
                        if( !pyobj )
 
340
                                return ( EXPP_ReturnPyObjError
 
341
                                         ( PyExc_MemoryError,
 
342
                                           "couldn't create PyString" ) );
 
343
 
 
344
                        PyList_SET_ITEM( latlist, index, pyobj );
 
345
 
 
346
                        lat_iter = lat_iter->id.next;
 
347
                        index++;
 
348
                }
 
349
 
 
350
                return ( latlist );
 
351
        }
166
352
}
167
 
//***************************************************************************
168
 
// Function:                                                    Lattice_Init                                                                                                                                                                    
169
 
//***************************************************************************
170
 
PyObject *Lattice_Init (void)
 
353
 
 
354
//***************************************************************************
 
355
// Function:       Lattice_Init   
 
356
//***************************************************************************
 
357
PyObject *Lattice_Init( void )
171
358
{
172
 
        PyObject *mod= Py_InitModule3("Blender.Lattice", M_Lattice_methods, M_Lattice_doc);
173
 
        PyObject *dict= PyModule_GetDict(mod);
 
359
        PyObject *mod =
 
360
                Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
 
361
                                M_Lattice_doc );
 
362
        PyObject *dict = PyModule_GetDict( mod );
174
363
 
175
364
        Lattice_Type.ob_type = &PyType_Type;
176
365
 
177
366
        //Module dictionary
178
 
        #define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(LT_##x))
179
 
        EXPP_ADDCONST(GRID);
180
 
        EXPP_ADDCONST(OUTSIDE);
181
 
 
182
 
        #undef EXPP_ADDCONST
183
 
        #define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(KEY_##x))
184
 
        EXPP_ADDCONST(LINEAR);
185
 
        EXPP_ADDCONST(CARDINAL);
186
 
        EXPP_ADDCONST(BSPLINE);
187
 
 
188
 
        return(mod);
 
367
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(LT_##x))
 
368
        EXPP_ADDCONST( GRID );
 
369
        EXPP_ADDCONST( OUTSIDE );
 
370
 
 
371
#undef EXPP_ADDCONST
 
372
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(KEY_##x))
 
373
        EXPP_ADDCONST( LINEAR );
 
374
        EXPP_ADDCONST( CARDINAL );
 
375
        EXPP_ADDCONST( BSPLINE );
 
376
 
 
377
        return ( mod );
189
378
}
190
379
 
191
380
//***************************************************************************
192
 
// Python BPy_Lattice methods:                                                                                                                                                                                                  
 
381
// Python BPy_Lattice methods:                      
193
382
//***************************************************************************
194
 
static PyObject *Lattice_getName(BPy_Lattice *self)
 
383
static PyObject *Lattice_getName( BPy_Lattice * self )
195
384
{
196
 
        PyObject *attr = PyString_FromString(self->Lattice->id.name+2);
197
 
 
198
 
        if (attr) return attr;
199
 
 
200
 
        return EXPP_ReturnPyObjError (PyExc_RuntimeError,
201
 
                        "couldn't get Lattice.name attribute");
 
385
        PyObject *attr = PyString_FromString( self->Lattice->id.name + 2 );
 
386
 
 
387
        if( attr )
 
388
                return attr;
 
389
 
 
390
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
391
                                      "couldn't get Lattice.name attribute" );
202
392
}
203
393
 
204
 
static PyObject *Lattice_setName(BPy_Lattice *self, PyObject *args)
 
394
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args )
205
395
{
206
396
        char *name;
207
397
        char buf[21];
208
398
 
209
 
        if (!PyArg_ParseTuple(args, "s", &name))
210
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError,
211
 
                "expected string argument"));
212
 
 
213
 
        PyOS_snprintf(buf, sizeof(buf), "%s", name);
214
 
 
215
 
        rename_id(&self->Lattice->id, buf);
216
 
 
217
 
        Py_INCREF(Py_None);
 
399
        if( !PyArg_ParseTuple( args, "s", &name ) )
 
400
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
401
                                                "expected string argument" ) );
 
402
 
 
403
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
 
404
 
 
405
        rename_id( &self->Lattice->id, buf );
 
406
 
 
407
        Py_INCREF( Py_None );
218
408
        return Py_None;
219
409
}
220
410
 
221
 
static PyObject *Lattice_setPartitions(BPy_Lattice *self, PyObject *args)
 
411
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
222
412
{
223
413
        int x = 0;
224
414
        int y = 0;
225
415
        int z = 0;
226
 
        Lattice  * bl_Lattice;
 
416
        Lattice *bl_Lattice;
227
417
 
228
 
        if (!PyArg_ParseTuple(args, "iii", &x, &y, &z))
229
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
230
 
                        "expected int,int,int argument"));
 
418
        if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
 
419
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
420
                                                "expected int,int,int argument" ) );
231
421
 
232
422
        bl_Lattice = self->Lattice;
233
423
 
234
 
        if(x <2 || y < 2 || z < 2)
235
 
                return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
236
 
                        "partition values must be 2 or greater"));
237
 
 
238
 
        bl_Lattice->pntsu = (short)x;
239
 
        bl_Lattice->pntsv = (short)y;
240
 
        bl_Lattice->pntsw = (short)z;
241
 
        resizelattice(bl_Lattice);
242
 
 
243
 
        Py_INCREF (Py_None);
 
424
        if( x < 2 || y < 2 || z < 2 )
 
425
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
426
                                                "partition values must be 2 or greater" ) );
 
427
 
 
428
        bl_Lattice->pntsu = ( short ) x;
 
429
        bl_Lattice->pntsv = ( short ) y;
 
430
        bl_Lattice->pntsw = ( short ) z;
 
431
        resizelattice( bl_Lattice );
 
432
 
 
433
        Py_INCREF( Py_None );
244
434
        return Py_None;
245
435
}
246
436
 
247
 
static PyObject *Lattice_getPartitions(BPy_Lattice *self, PyObject *args)
 
437
static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args )
248
438
{
249
 
        Lattice  * bl_Lattice;
 
439
        Lattice *bl_Lattice;
250
440
        bl_Lattice = self->Lattice;
251
441
 
252
 
        return Py_BuildValue("[i,i,i]", (int)bl_Lattice->pntsu,
253
 
                                                                        (int)bl_Lattice->pntsv,
254
 
                                                                        (int)bl_Lattice->pntsw);
 
442
        return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
 
443
                              ( int ) bl_Lattice->pntsv,
 
444
                              ( int ) bl_Lattice->pntsw );
255
445
}
256
 
                
257
 
static PyObject *Lattice_getKeyTypes(BPy_Lattice *self, PyObject *args)
 
446
 
 
447
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args )
258
448
{
259
 
        Lattice  * bl_Lattice;
 
449
        Lattice *bl_Lattice;
260
450
        char *linear = "linear";
261
451
        char *cardinal = "cardinal";
262
452
        char *bspline = "bspline";
264
454
 
265
455
        bl_Lattice = self->Lattice;
266
456
 
267
 
        if ((bl_Lattice->typeu) == KEY_LINEAR)
 
457
        if( ( bl_Lattice->typeu ) == KEY_LINEAR )
268
458
                s_x = linear;
269
 
        else if ((bl_Lattice->typeu) == KEY_CARDINAL)
 
459
        else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
270
460
                s_x = cardinal;
271
 
        else if ((bl_Lattice->typeu) == KEY_BSPLINE)
 
461
        else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
272
462
                s_x = bspline;
273
463
        else
274
 
                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
275
 
                         "bad key type...");
 
464
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
465
                                              "bad key type..." );
276
466
 
277
 
        if ((bl_Lattice->typev) == KEY_LINEAR)
 
467
        if( ( bl_Lattice->typev ) == KEY_LINEAR )
278
468
                s_y = linear;
279
 
        else if ((bl_Lattice->typev) == KEY_CARDINAL)
 
469
        else if( ( bl_Lattice->typev ) == KEY_CARDINAL )
280
470
                s_y = cardinal;
281
 
        else if ((bl_Lattice->typev) == KEY_BSPLINE)
 
471
        else if( ( bl_Lattice->typev ) == KEY_BSPLINE )
282
472
                s_z = bspline;
283
473
        else
284
 
                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
285
 
                         "bad key type...");
 
474
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
475
                                              "bad key type..." );
286
476
 
287
 
        if ((bl_Lattice->typew) == KEY_LINEAR)
 
477
        if( ( bl_Lattice->typew ) == KEY_LINEAR )
288
478
                s_z = linear;
289
 
        else if ((bl_Lattice->typew) == KEY_CARDINAL)
 
479
        else if( ( bl_Lattice->typew ) == KEY_CARDINAL )
290
480
                s_z = cardinal;
291
 
        else if ((bl_Lattice->typew) == KEY_BSPLINE)
 
481
        else if( ( bl_Lattice->typew ) == KEY_BSPLINE )
292
482
                s_z = bspline;
293
483
        else
294
 
                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
295
 
                         "bad key type...");
 
484
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
485
                                              "bad key type..." );
296
486
 
297
487
        /* we made sure no s_[xyz] is NULL */
298
 
        return Py_BuildValue("[s,s,s]", s_x, s_y, s_z);
 
488
        return Py_BuildValue( "[s,s,s]", s_x, s_y, s_z );
299
489
}
300
490
 
301
 
static PyObject *Lattice_setKeyTypes(BPy_Lattice *self, PyObject *args)
 
491
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args )
302
492
{
303
493
        int x;
304
494
        int y;
305
495
        int z;
306
 
        Lattice  * bl_Lattice;
 
496
        Lattice *bl_Lattice;
307
497
 
308
 
        if (!PyArg_ParseTuple(args, "iii", &x, &y, &z))
309
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
310
 
                                                "expected int,int,int argument"));
 
498
        if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
 
499
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
500
                                                "expected int,int,int argument" ) );
311
501
 
312
502
        bl_Lattice = self->Lattice;
313
 
        
314
 
        if (x == KEY_LINEAR)
 
503
 
 
504
        if( x == KEY_LINEAR )
315
505
                bl_Lattice->typeu = KEY_LINEAR;
316
 
        else if (x == KEY_CARDINAL)
 
506
        else if( x == KEY_CARDINAL )
317
507
                bl_Lattice->typeu = KEY_CARDINAL;
318
 
        else if (x == KEY_BSPLINE)
 
508
        else if( x == KEY_BSPLINE )
319
509
                bl_Lattice->typeu = KEY_BSPLINE;
320
510
        else
321
 
                return EXPP_ReturnPyObjError (PyExc_TypeError,
322
 
                                                 "type must be LINEAR, CARDINAL OR BSPLINE");
 
511
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
512
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
323
513
 
324
 
        if (y == KEY_LINEAR)
 
514
        if( y == KEY_LINEAR )
325
515
                bl_Lattice->typev = KEY_LINEAR;
326
 
        else if (y == KEY_CARDINAL)
 
516
        else if( y == KEY_CARDINAL )
327
517
                bl_Lattice->typev = KEY_CARDINAL;
328
 
        else if (y == KEY_BSPLINE)
 
518
        else if( y == KEY_BSPLINE )
329
519
                bl_Lattice->typev = KEY_BSPLINE;
330
520
        else
331
 
                return EXPP_ReturnPyObjError (PyExc_TypeError,
332
 
                                                 "type must be LINEAR, CARDINAL OR BSPLINE");
 
521
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
522
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
333
523
 
334
 
        if (z == KEY_LINEAR)
 
524
        if( z == KEY_LINEAR )
335
525
                bl_Lattice->typew = KEY_LINEAR;
336
 
        else if (z == KEY_CARDINAL)
 
526
        else if( z == KEY_CARDINAL )
337
527
                bl_Lattice->typew = KEY_CARDINAL;
338
 
        else if (z == KEY_BSPLINE)
 
528
        else if( z == KEY_BSPLINE )
339
529
                bl_Lattice->typew = KEY_BSPLINE;
340
530
        else
341
 
                return EXPP_ReturnPyObjError (PyExc_TypeError,
342
 
                                                 "type must be LINEAR, CARDINAL OR BSPLINE");
 
531
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
532
                                              "type must be LINEAR, CARDINAL OR BSPLINE" );
343
533
 
344
 
        Py_INCREF(Py_None);
 
534
        Py_INCREF( Py_None );
345
535
        return Py_None;
346
536
}
347
537
 
348
 
static PyObject *Lattice_setMode(BPy_Lattice *self, PyObject *args)
 
538
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args )
349
539
{
350
540
        short type;
351
 
        Lattice  * bl_Lattice;
 
541
        Lattice *bl_Lattice;
352
542
        bl_Lattice = self->Lattice;
353
543
 
354
 
        if (!PyArg_ParseTuple(args, "h", &type))
355
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
356
 
                                                "expected string argument"));
 
544
        if( !PyArg_ParseTuple( args, "h", &type ) )
 
545
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
546
                                                "expected string argument" ) );
357
547
 
358
 
        if (type == LT_GRID)
 
548
        if( type == LT_GRID )
359
549
                bl_Lattice->flag = LT_GRID;
360
 
        else if (type == LT_OUTSIDE)
361
 
        {
 
550
        else if( type == LT_OUTSIDE ) {
362
551
                bl_Lattice->flag = LT_OUTSIDE + LT_GRID;
363
 
                outside_lattice(bl_Lattice);
364
 
        }
365
 
         else
366
 
                return EXPP_ReturnPyObjError (PyExc_TypeError,
367
 
                                                 "type must be either GRID or OUTSIDE");
 
552
                outside_lattice( bl_Lattice );
 
553
        } else
 
554
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
555
                                              "type must be either GRID or OUTSIDE" );
368
556
 
369
 
        Py_INCREF(Py_None);
 
557
        Py_INCREF( Py_None );
370
558
        return Py_None;
371
559
}
372
560
 
373
 
static PyObject *Lattice_getMode(BPy_Lattice *self, PyObject *args)
 
561
static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args )
374
562
{
375
563
        char type[24];
376
 
        Lattice  * bl_Lattice;
 
564
        Lattice *bl_Lattice;
377
565
        bl_Lattice = self->Lattice;
378
566
 
379
 
        if (bl_Lattice->flag & LT_GRID)
380
 
        sprintf(type, "Grid");
381
 
        else if (bl_Lattice->flag & LT_OUTSIDE)
382
 
        sprintf(type, "Outside");
 
567
        if( bl_Lattice->flag & LT_GRID )
 
568
                sprintf( type, "Grid" );
 
569
        else if( bl_Lattice->flag & LT_OUTSIDE )
 
570
                sprintf( type, "Outside" );
383
571
        else
384
 
                return EXPP_ReturnPyObjError (PyExc_TypeError,
385
 
                                                 "bad mode type...");
386
 
 
387
 
        return Py_BuildValue("s", type);
 
572
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
573
                                              "bad mode type..." );
 
574
 
 
575
        return Py_BuildValue( "s", type );
388
576
}
389
577
 
390
 
static PyObject *Lattice_setPoint(BPy_Lattice *self, PyObject *args)
 
578
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args )
391
579
{
392
580
        BPoint *bp, *bpoint;
393
581
        short size;
394
 
        Lattice  * bl_Lattice;
 
582
        Lattice *bl_Lattice;
395
583
        int index, x;
396
584
        float tempInt;
397
 
        PyObject * listObject;
398
 
 
399
 
        if (!PyArg_ParseTuple(args, "iO!", &index, &PyList_Type, &listObject))
400
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
401
 
                                                "expected int & list argument"));
402
 
 
403
 
        if(!PyList_Check(listObject))
404
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
405
 
                                                "2nd parameter should be a python list"));
406
 
 
407
 
        if (!(PyList_Size(listObject) == 3))
408
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
409
 
                                                "Please pass 3 parameters in the list [x,y,z]"));
 
585
        PyObject *listObject;
 
586
 
 
587
        if( !PyArg_ParseTuple
 
588
            ( args, "iO!", &index, &PyList_Type, &listObject ) )
 
589
                return ( EXPP_ReturnPyObjError
 
590
                         ( PyExc_TypeError, "expected int & list argument" ) );
 
591
 
 
592
        if( !PyList_Check( listObject ) )
 
593
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
594
                                                "2nd parameter should be a python list" ) );
 
595
 
 
596
        if( !( PyList_Size( listObject ) == 3 ) )
 
597
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
598
                                                "Please pass 3 parameters in the list [x,y,z]" ) );
410
599
 
411
600
        //init
412
 
        bp= 0;
 
601
        bp = 0;
413
602
        bl_Lattice = self->Lattice;
414
603
 
415
604
        //get bpoints
416
 
        bp= bl_Lattice->def;
417
 
 
418
 
        if(bp == 0)
419
 
                return (EXPP_ReturnPyObjError (PyExc_AttributeError,
420
 
                                                "no lattice points!"));
421
 
        
 
605
        bp = bl_Lattice->def;
 
606
 
 
607
        if( bp == 0 )
 
608
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
609
                                                "no lattice points!" ) );
 
610
 
422
611
        //calculate size of lattice
423
 
        size= bl_Lattice->pntsu*bl_Lattice->pntsv*bl_Lattice->pntsw;
424
 
 
425
 
        if (index < 0 || index > size)
426
 
                return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
427
 
                                                "index outside of lattice size!"));
428
 
        
 
612
        size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
 
613
 
 
614
        if( index < 0 || index > size )
 
615
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
616
                                                "index outside of lattice size!" ) );
 
617
 
429
618
        //get the bpoint
430
 
        while (index)
431
 
        {
 
619
        while( index ) {
432
620
                index--;
433
621
                bp++;
434
622
        }
435
623
        bpoint = bp;
436
624
 
437
 
        for (x = 0; x < PyList_Size(listObject); x++) {
438
 
                if (!(PyArg_Parse((PyList_GetItem(listObject, x)), "f", &tempInt)))
439
 
                        return EXPP_ReturnPyObjError (PyExc_TypeError,
440
 
                                                                                        "python list integer not parseable");
 
625
        for( x = 0; x < PyList_Size( listObject ); x++ ) {
 
626
                if( !
 
627
                    ( PyArg_Parse
 
628
                      ( ( PyList_GetItem( listObject, x ) ), "f",
 
629
                        &tempInt ) ) )
 
630
                        return EXPP_ReturnPyObjError( PyExc_TypeError,
 
631
                                                      "python list integer not parseable" );
441
632
                bpoint->vec[x] = tempInt;
442
633
        }
443
634
 
444
 
        Py_INCREF(Py_None);
 
635
        Py_INCREF( Py_None );
445
636
        return Py_None;
446
637
}
447
638
 
448
 
static PyObject *Lattice_getPoint(BPy_Lattice *self, PyObject *args)
 
639
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
449
640
{
450
641
        BPoint *bp, *bpoint;
451
642
        short size;
452
 
        Lattice  * bl_Lattice;
 
643
        Lattice *bl_Lattice;
453
644
        int index;
454
645
 
455
 
        if (!PyArg_ParseTuple(args, "i", &index))
456
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
457
 
                                                "expected int argument"));
 
646
        if( !PyArg_ParseTuple( args, "i", &index ) )
 
647
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
648
                                                "expected int argument" ) );
458
649
 
459
650
        //init
460
 
        bp= 0;
 
651
        bp = 0;
461
652
        bl_Lattice = self->Lattice;
462
653
 
463
654
        //get bpoints
464
 
        bp= bl_Lattice->def;
465
 
 
466
 
        if(bp == 0)
467
 
                return (EXPP_ReturnPyObjError (PyExc_AttributeError,
468
 
                                                "no lattice points!"));
469
 
        
 
655
        bp = bl_Lattice->def;
 
656
 
 
657
        if( bp == 0 )
 
658
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
659
                                                "no lattice points!" ) );
 
660
 
470
661
        //calculate size of lattice
471
 
        size= bl_Lattice->pntsu*bl_Lattice->pntsv*bl_Lattice->pntsw;
472
 
 
473
 
        if (index < 0 || index > size)
474
 
                return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
475
 
                                                "index outside of lattice size!"));
476
 
        
 
662
        size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
 
663
 
 
664
        if( index < 0 || index > size )
 
665
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
666
                                                "index outside of lattice size!" ) );
 
667
 
477
668
        //get the bpoint
478
 
        while (index)
479
 
        {
 
669
        while( index ) {
480
670
                index--;
481
671
                bp++;
482
672
        }
483
673
        bpoint = bp;
484
674
 
485
 
        if(bpoint == 0)
486
 
                return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
487
 
                                                "bpoint does not exist"));
 
675
        if( bpoint == 0 )
 
676
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
677
                                                "bpoint does not exist" ) );
488
678
 
489
 
        return Py_BuildValue("[f,f,f]", bp->vec[0] ,bp->vec[1] ,bp->vec[2]);
 
679
        return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
490
680
}
491
681
 
492
682
//This function will not do anything if there are no children
493
 
static PyObject *Lattice_applyDeform(BPy_Lattice *self)
 
683
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args )
494
684
{
495
685
        //Object* ob; unused
496
686
        Base *base;
497
687
        Object *par;
498
 
 
499
 
        if (!Lattice_IsLinkedToObject(self))
500
 
                return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
501
 
                                                "Lattice must be linked to an object to apply it's deformation!"));
502
 
 
503
 
        //deform children
504
 
        base= FIRSTBASE;
505
 
        while(base) {
506
 
                if( (par= base->object->parent) ) {
507
 
                        if(par->type==OB_LATTICE) {             
508
 
                                        object_deform(base->object);                    
509
 
                                }
510
 
                        }                       
511
 
                base= base->next;
 
688
        int forced = 0;
 
689
 
 
690
        if( !Lattice_IsLinkedToObject( self ) )
 
691
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
692
                                                "Lattice must be linked to an object to apply it's deformation!" ) );
 
693
 
 
694
        if( !PyArg_ParseTuple( args, "|i", &forced ) )
 
695
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
696
                                                "expected nothing or True or False argument" ) );
 
697
 
 
698
        /* deform children */
 
699
        base = FIRSTBASE;
 
700
        while( base ) {
 
701
                if( ( par = base->object->parent ) ) { /* check/assign if ob has parent */
 
702
                        /* meshes have their mverts deformed, others ob types use displist,
 
703
                         * so we're not doing meshes here (unless forced), or else they get
 
704
                         * deformed twice, since parenting a Lattice to an object and redrawing
 
705
                         * already applies lattice deformation. 'forced' is useful for
 
706
                         * command line background mode, when no redraws occur and so this
 
707
                         * method is needed.  Or for users who actually want to apply the
 
708
                         * deformation n times. */
 
709
                        if((self->Lattice == par->data)) {
 
710
                                if ((base->object->type != OB_MESH) || forced)
 
711
                                        object_deform( base->object );
 
712
                        }
 
713
                }
 
714
                base = base->next;
512
715
        }
513
716
 
514
 
        Py_INCREF(Py_None);
 
717
        Py_INCREF( Py_None );
515
718
        return Py_None;
516
719
}
517
720
 
518
 
static PyObject *Lattice_insertKey(BPy_Lattice *self, PyObject *args)
 
721
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
519
722
{
520
723
        Lattice *lt;
521
724
        int frame = -1, oldfra = -1;
522
725
 
523
 
        if (!PyArg_ParseTuple(args, "i", &frame))
524
 
                return (EXPP_ReturnPyObjError (PyExc_TypeError,
525
 
                                                "expected int argument"));
 
726
        if( !PyArg_ParseTuple( args, "i", &frame ) )
 
727
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
728
                                                "expected int argument" ) );
526
729
 
527
730
        lt = self->Lattice;
528
731
 
529
732
        //set the current frame
530
 
        if (frame > 0) {
531
 
                frame = EXPP_ClampInt (frame, 1, 18000);
 
733
        if( frame > 0 ) {
 
734
                frame = EXPP_ClampInt( frame, 1, MAXFRAME );
532
735
                oldfra = G.scene->r.cfra;
533
736
                G.scene->r.cfra = frame;
534
737
        }
535
 
//      else just use current frame, then
536
 
//              return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
537
 
//                                              "frame value has to be greater than 0"));
 
738
//      else just use current frame, then
 
739
//              return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
 
740
//                                              "frame value has to be greater than 0"));
538
741
 
539
742
        //insert a keybock for the lattice
540
 
        insert_lattkey(lt);
541
 
 
542
 
        if (frame > 0) G.scene->r.cfra = oldfra;
543
 
 
544
 
        Py_INCREF(Py_None);
 
743
        insert_lattkey( lt );
 
744
 
 
745
        if( frame > 0 )
 
746
                G.scene->r.cfra = oldfra;
 
747
 
 
748
        Py_INCREF( Py_None );
545
749
        return Py_None;
546
750
}
547
751
 
548
752
//***************************************************************************
549
 
// Function:            Lattice_dealloc                                                                                                                                                                                                 
550
 
// Description: This is a callback function for the BPy_Lattice type. It is                     
551
 
//                                                      the destructor function.                                                                                                                                                 
 
753
// Function:      Lattice_dealloc  
 
754
// Description: This is a callback function for the BPy_Lattice type. It is 
 
755
//          the destructor function.      
552
756
//***************************************************************************
553
 
static void Lattice_dealloc (BPy_Lattice *self)
 
757
static void Lattice_dealloc( BPy_Lattice * self )
554
758
{
555
 
        PyObject_DEL (self);
 
759
        PyObject_DEL( self );
556
760
}
557
761
 
558
762
//***************************************************************************
559
 
// Function:            Lattice_getAttr                                                                                                                                                                                                 
560
 
// Description: This is a callback function for the BPy_Lattice type. It is                     
561
 
//                                                      the function that accesses BPy_Lattice member variables and                     
562
 
//                                                      methods.                                                                                                                                                                                                                 
 
763
// Function:         Lattice_getAttr   
 
764
// Description: This is a callback function for the BPy_Lattice type. It is 
 
765
//                the function that accesses BPy_Lattice member variables and 
 
766
//                 methods.  
563
767
//***************************************************************************
564
 
static PyObject *Lattice_getAttr (BPy_Lattice *self, char *name)
 
768
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
565
769
{
566
770
        PyObject *attr = Py_None;
567
771
 
568
 
        if (!self->Lattice || !Lattice_InLatList(self))
569
 
                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
570
 
                         "Lattice was already deleted!");
571
 
 
572
 
        if (strcmp(name, "name") == 0)
573
 
                attr = PyString_FromString(self->Lattice->id.name+2);
574
 
        else if (strcmp(name, "width") == 0)
575
 
                attr = Py_BuildValue("i",self->Lattice->pntsu);
576
 
        else if (strcmp(name, "height") == 0)
577
 
                attr = Py_BuildValue("i",self->Lattice->pntsv);
578
 
        else if (strcmp(name, "depth") == 0)
579
 
                attr = Py_BuildValue("i",self->Lattice->pntsw);
580
 
        else if (strcmp(name, "widthType") == 0)
581
 
        {
582
 
                if(self->Lattice->typeu == 0)
583
 
                        attr = Py_BuildValue("s","Linear");
584
 
                else if (self->Lattice->typeu == 1)
585
 
                        attr = Py_BuildValue("s","Cardinal");
586
 
                else if (self->Lattice->typeu == 2)
587
 
                        attr = Py_BuildValue("s","Bspline");
588
 
                else
589
 
                        return EXPP_ReturnPyObjError (PyExc_ValueError,
590
 
                                "bad widthType...");
591
 
        }
592
 
        else if (strcmp(name, "heightType") == 0)
593
 
        {
594
 
                if(self->Lattice->typev == 0)
595
 
                        attr = Py_BuildValue("s","Linear");
596
 
                else if (self->Lattice->typev== 1)
597
 
                        attr = Py_BuildValue("s","Cardinal");
598
 
                else if (self->Lattice->typev == 2)
599
 
                        attr = Py_BuildValue("s","Bspline");
600
 
                else
601
 
                        return EXPP_ReturnPyObjError (PyExc_ValueError,
602
 
                                "bad widthType...");
603
 
        }
604
 
        else if (strcmp(name, "depthType") == 0)
605
 
        {
606
 
                if(self->Lattice->typew == 0)
607
 
                        attr = Py_BuildValue("s","Linear");
608
 
                else if (self->Lattice->typew == 1)
609
 
                        attr = Py_BuildValue("s","Cardinal");
610
 
                else if (self->Lattice->typew == 2)
611
 
                        attr = Py_BuildValue("s","Bspline");
612
 
                else
613
 
                        return EXPP_ReturnPyObjError (PyExc_ValueError,
614
 
                                "bad widthType...");
615
 
        }
616
 
        else if (strcmp(name, "mode") == 0)
617
 
        {
618
 
                if(self->Lattice->flag == 1)
619
 
                        attr = Py_BuildValue("s","Grid");
620
 
                else if (self->Lattice->flag == 3)
621
 
                        attr = Py_BuildValue("s","Outside");
622
 
                else
623
 
                        return EXPP_ReturnPyObjError (PyExc_ValueError,
624
 
                                "bad mode...");
625
 
        }
626
 
        else if (strcmp(name, "latSize") == 0)
627
 
        {
628
 
                attr = Py_BuildValue("i",self->Lattice->pntsu * 
629
 
                                                                 self->Lattice->pntsv *
630
 
                                                                 self->Lattice->pntsw);
631
 
        }
632
 
        else if (strcmp(name, "__members__") == 0)
633
 
                attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s]", "name","width","height","depth",
634
 
        "widthType","heightType","depthType","mode","latSize");
635
 
 
636
 
        if (!attr)
637
 
                return (EXPP_ReturnPyObjError (PyExc_MemoryError,
638
 
                                                                                                                "couldn't create PyObject"));
639
 
 
640
 
        if (attr != Py_None) return attr; // attribute found, return its value 
 
772
        if( !self->Lattice || !Lattice_InLatList( self ) )
 
773
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
774
                                              "Lattice was already deleted!" );
 
775
 
 
776
        if( strcmp( name, "name" ) == 0 )
 
777
                attr = PyString_FromString( self->Lattice->id.name + 2 );
 
778
        else if( strcmp( name, "width" ) == 0 )
 
779
                attr = Py_BuildValue( "i", self->Lattice->pntsu );
 
780
        else if( strcmp( name, "height" ) == 0 )
 
781
                attr = Py_BuildValue( "i", self->Lattice->pntsv );
 
782
        else if( strcmp( name, "depth" ) == 0 )
 
783
                attr = Py_BuildValue( "i", self->Lattice->pntsw );
 
784
        else if( strcmp( name, "widthType" ) == 0 ) {
 
785
                if( self->Lattice->typeu == 0 )
 
786
                        attr = Py_BuildValue( "s", "Linear" );
 
787
                else if( self->Lattice->typeu == 1 )
 
788
                        attr = Py_BuildValue( "s", "Cardinal" );
 
789
                else if( self->Lattice->typeu == 2 )
 
790
                        attr = Py_BuildValue( "s", "Bspline" );
 
791
                else
 
792
                        return EXPP_ReturnPyObjError( PyExc_ValueError,
 
793
                                                      "bad widthType..." );
 
794
        } else if( strcmp( name, "heightType" ) == 0 ) {
 
795
                if( self->Lattice->typev == 0 )
 
796
                        attr = Py_BuildValue( "s", "Linear" );
 
797
                else if( self->Lattice->typev == 1 )
 
798
                        attr = Py_BuildValue( "s", "Cardinal" );
 
799
                else if( self->Lattice->typev == 2 )
 
800
                        attr = Py_BuildValue( "s", "Bspline" );
 
801
                else
 
802
                        return EXPP_ReturnPyObjError( PyExc_ValueError,
 
803
                                                      "bad widthType..." );
 
804
        } else if( strcmp( name, "depthType" ) == 0 ) {
 
805
                if( self->Lattice->typew == 0 )
 
806
                        attr = Py_BuildValue( "s", "Linear" );
 
807
                else if( self->Lattice->typew == 1 )
 
808
                        attr = Py_BuildValue( "s", "Cardinal" );
 
809
                else if( self->Lattice->typew == 2 )
 
810
                        attr = Py_BuildValue( "s", "Bspline" );
 
811
                else
 
812
                        return EXPP_ReturnPyObjError( PyExc_ValueError,
 
813
                                                      "bad widthType..." );
 
814
        } else if( strcmp( name, "mode" ) == 0 ) {
 
815
                if( self->Lattice->flag == 1 )
 
816
                        attr = Py_BuildValue( "s", "Grid" );
 
817
                else if( self->Lattice->flag == 3 )
 
818
                        attr = Py_BuildValue( "s", "Outside" );
 
819
                else
 
820
                        return EXPP_ReturnPyObjError( PyExc_ValueError,
 
821
                                                      "bad mode..." );
 
822
        } else if( strcmp( name, "latSize" ) == 0 ) {
 
823
                attr = Py_BuildValue( "i", self->Lattice->pntsu *
 
824
                                      self->Lattice->pntsv *
 
825
                                      self->Lattice->pntsw );
 
826
        } else if( strcmp( name, "users" ) == 0 ) {
 
827
                attr = PyInt_FromLong( self->Lattice->id.us );
 
828
        
 
829
        } else if( strcmp( name, "__members__" ) == 0 )
 
830
                attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s]", "name", "width",
 
831
                                      "height", "depth", "widthType",
 
832
                                      "heightType", "depthType", "mode",
 
833
                                      "latSize", "users" );
 
834
        
 
835
        if( !attr )
 
836
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
837
                                                "couldn't create PyObject" ) );
 
838
 
 
839
        if( attr != Py_None )
 
840
                return attr;    // attribute found, return its value 
641
841
 
642
842
        // not an attribute, search the methods table 
643
 
        return Py_FindMethod(BPy_Lattice_methods, (PyObject *)self, name);
 
843
        return Py_FindMethod( BPy_Lattice_methods, ( PyObject * ) self, name );
644
844
}
645
845
 
646
846
//***************************************************************************
647
 
// Function:            Lattice_setAttr                                                                                                                                                                                                 
648
 
// Description: This is a callback function for the BPy_Lattice type. It is the 
649
 
//                                                      function that changes Lattice Data members values. If this                      
650
 
//                                                      data is linked to a Blender Lattice, it also gets updated.                      
 
847
// Function:            Lattice_setAttr  
 
848
// Description: This is a callback function for the BPy_Lattice type. It is the
 
849
//                function that changes Lattice Data members values. If this 
 
850
//                  data is linked to a Blender Lattice, it also gets updated.
651
851
//***************************************************************************
652
 
static int Lattice_setAttr (BPy_Lattice *self, char *name, PyObject *value)
 
852
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * value )
653
853
{
654
 
        PyObject *valtuple; 
 
854
        PyObject *valtuple;
655
855
        PyObject *error = NULL;
656
856
 
657
 
        if (!self->Lattice || !Lattice_InLatList(self))
658
 
                return EXPP_ReturnIntError (PyExc_RuntimeError,
659
 
                         "Lattice was already deleted!");
660
 
 
661
 
        valtuple = Py_BuildValue("(O)", value);// the set* functions expect a tuple 
662
 
 
663
 
        if (!valtuple)
664
 
                return EXPP_ReturnIntError(PyExc_MemoryError,
665
 
                                                                        "LatticeSetAttr: couldn't create PyTuple");
666
 
 
667
 
        if (strcmp (name, "name") == 0)
668
 
                error = Lattice_setName (self, valtuple);
669
 
        else { // Error: no such member in the Lattice Data structure 
670
 
                Py_DECREF(value);
671
 
                Py_DECREF(valtuple);
672
 
                return (EXPP_ReturnIntError (PyExc_KeyError,
673
 
                                                "attribute not found or immutable"));
 
857
        if( !self->Lattice || !Lattice_InLatList( self ) )
 
858
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
859
                                            "Lattice was already deleted!" );
 
860
 
 
861
        valtuple = Py_BuildValue( "(O)", value );       // the set* functions expect a tuple 
 
862
 
 
863
        if( !valtuple )
 
864
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
865
                                            "LatticeSetAttr: couldn't create PyTuple" );
 
866
 
 
867
        if( strcmp( name, "name" ) == 0 )
 
868
                error = Lattice_setName( self, valtuple );
 
869
        else {                  // Error: no such member in the Lattice Data structure 
 
870
                Py_DECREF( value );
 
871
                Py_DECREF( valtuple );
 
872
                return ( EXPP_ReturnIntError( PyExc_KeyError,
 
873
                                              "attribute not found or immutable" ) );
674
874
        }
675
 
        Py_DECREF(valtuple);
676
 
 
677
 
        if (error != Py_None) return -1;
678
 
 
679
 
        return 0; // normal exit 
 
875
        Py_DECREF( valtuple );
 
876
 
 
877
        if( error != Py_None )
 
878
                return -1;
 
879
 
 
880
        return 0;               // normal exit 
680
881
}
681
882
 
682
883
//***************************************************************************
683
 
// Function:            Lattice_repr                                                                                                                                                                                                            
684
 
// Description: This is a callback function for the BPy_Lattice type. It                                
685
 
//                                                      builds a meaninful string to represent Lattice objects.                                 
 
884
// Function:  Lattice_repr   
 
885
// Description: This is a callback function for the BPy_Lattice type. It 
 
886
//                  builds a meaninful string to represent Lattice objects. 
686
887
//***************************************************************************
687
 
static PyObject *Lattice_repr (BPy_Lattice *self)
 
888
static PyObject *Lattice_repr( BPy_Lattice * self )
688
889
{
689
 
        if (self->Lattice && Lattice_InLatList(self))
690
 
                return PyString_FromFormat("[Lattice \"%s\"]", self->Lattice->id.name+2);
 
890
        if( self->Lattice && Lattice_InLatList( self ) )
 
891
                return PyString_FromFormat( "[Lattice \"%s\"]",
 
892
                                            self->Lattice->id.name + 2 );
691
893
        else
692
 
                return PyString_FromString("[Lattice <deleted>]");
 
894
                return PyString_FromString( "[Lattice <deleted>]" );
693
895
}
694
896
 
695
897
//***************************************************************************
696
 
// Function:            Internal Lattice functions      
 
898
// Function:            Internal Lattice functions      
697
899
//***************************************************************************
698
900
// Internal function to confirm if a Lattice wasn't unlinked from main.
699
 
static int Lattice_InLatList(BPy_Lattice *self)
 
901
static int Lattice_InLatList( BPy_Lattice * self )
700
902
{
701
903
        Lattice *lat_iter = G.main->latt.first;
702
904
 
703
 
        while (lat_iter) {
704
 
                if (self->Lattice == lat_iter) return 1; // ok, still linked 
 
905
        while( lat_iter ) {
 
906
                if( self->Lattice == lat_iter )
 
907
                        return 1;       // ok, still linked 
705
908
 
706
909
                lat_iter = lat_iter->id.next;
707
910
        }
708
911
        // uh-oh, it was already deleted 
709
 
        self->Lattice = NULL; // so we invalidate the pointer 
 
912
        self->Lattice = NULL;   // so we invalidate the pointer 
710
913
        return 0;
711
914
}
712
915
 
713
916
// Internal function to confirm if a Lattice has an object it's linked to.
714
 
static int Lattice_IsLinkedToObject(BPy_Lattice *self)
 
917
static int Lattice_IsLinkedToObject( BPy_Lattice * self )
715
918
{
716
919
        //check to see if lattice is linked to an object
717
 
        Object * ob= G.main->object.first;
718
 
        while(ob) {
719
 
                if(ob->type==OB_LATTICE){
720
 
                        if(self->Lattice == ob->data){
 
920
        Object *ob = G.main->object.first;
 
921
        while( ob ) {
 
922
                if( ob->type == OB_LATTICE ) {
 
923
                        if( self->Lattice == ob->data ) {
721
924
                                return 1;
722
925
                        }
723
 
                }                       
 
926
                }
724
927
                ob = ob->id.next;
725
928
        }
726
929
        return 0;