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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: CurNurb.c,v 1.20 2007/01/12 22:40:29 khughes Exp $
 
2
 * $Id: CurNurb.c,v 1.23 2007/03/15 01:47:51 campbellbarton Exp $
3
3
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
24
24
 *
25
25
 * This is a new part of Blender.
26
26
 *
27
 
 * Contributor(s): Stephen Swaney
 
27
 * Contributor(s): Stephen Swaney, Campbell Barton, Ken Hughes
28
28
 *
29
29
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
30
 */
37
37
#include "gen_utils.h"
38
38
#include "BezTriple.h"
39
39
 
40
 
 
41
40
/*
42
41
 * forward declarations go here
43
42
 */
44
43
 
45
 
 
46
44
static PyObject *M_CurNurb_New( PyObject * self, PyObject * args );
47
 
static PyObject *CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args );
 
45
static PyObject *CurNurb_oldsetMatIndex( BPy_CurNurb * self, PyObject * args );
 
46
static int CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args );
48
47
static PyObject *CurNurb_getMatIndex( BPy_CurNurb * self );
49
48
static PyObject *CurNurb_getFlagU( BPy_CurNurb * self );
50
 
static PyObject *CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args );
 
49
static PyObject *CurNurb_oldsetFlagU( BPy_CurNurb * self, PyObject * args );
 
50
static int CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args );
51
51
static PyObject *CurNurb_getFlagV( BPy_CurNurb * self );
52
 
static PyObject *CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args );
 
52
static PyObject *CurNurb_oldsetFlagV( BPy_CurNurb * self, PyObject * args );
 
53
static int CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args );
53
54
static PyObject *CurNurb_getType( BPy_CurNurb * self );
54
 
static PyObject *CurNurb_setType( BPy_CurNurb * self, PyObject * args );
 
55
static PyObject *CurNurb_oldsetType( BPy_CurNurb * self, PyObject * args );
 
56
static int CurNurb_setType( BPy_CurNurb * self, PyObject * args );
 
57
static PyObject *CurNurb_getKnotsU( BPy_CurNurb * self );
 
58
static PyObject *CurNurb_getKnotsV( BPy_CurNurb * self );
 
59
static PyObject *CurNurb_getPoints( BPy_CurNurb * self );
55
60
/* static PyObject* CurNurb_setXXX( BPy_CurNurb* self, PyObject* args ); */
56
61
static int CurNurb_setPoint( BPy_CurNurb * self, int index, PyObject * ob );
57
62
static int CurNurb_length( PyInstanceObject * inst );
72
77
  CurNurb_Type callback function prototypes:                          
73
78
*/
74
79
 
75
 
static void CurNurb_dealloc( BPy_CurNurb * self );
76
80
static int CurNurb_compare( BPy_CurNurb * a, BPy_CurNurb * b );
77
 
static PyObject *CurNurb_getAttr( BPy_CurNurb * self, char *name );
78
 
static int CurNurb_setAttr( BPy_CurNurb * self, char *name, PyObject * v );
79
81
static PyObject *CurNurb_repr( BPy_CurNurb * self );
80
82
 
81
 
 
82
 
 
83
83
/*
84
84
   table of module methods
85
85
   these are the equivalent of class or static methods.
108
108
static PyMethodDef BPy_CurNurb_methods[] = {
109
109
/*   name,     method,                    flags,         doc               */
110
110
/*  {"method", (PyCFunction) CurNurb_method, METH_NOARGS, " () - doc string"} */
111
 
        {"setMatIndex", ( PyCFunction ) CurNurb_setMatIndex, METH_VARARGS,
 
111
        {"setMatIndex", ( PyCFunction ) CurNurb_oldsetMatIndex, METH_VARARGS,
112
112
         "( index ) - set index into materials list"},
113
113
        {"getMatIndex", ( PyCFunction ) CurNurb_getMatIndex, METH_NOARGS,
114
114
         "( ) - get current material index"},
115
 
        {"setFlagU", ( PyCFunction ) CurNurb_setFlagU, METH_VARARGS,
 
115
        {"setFlagU", ( PyCFunction ) CurNurb_oldsetFlagU, METH_VARARGS,
116
116
         "( index ) - set flagU and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
117
117
        {"getFlagU", ( PyCFunction ) CurNurb_getFlagU, METH_NOARGS,
118
118
         "( ) - get flagU of the knots"},
119
 
        {"setFlagV", ( PyCFunction ) CurNurb_setFlagV, METH_VARARGS,
 
119
        {"setFlagV", ( PyCFunction ) CurNurb_oldsetFlagV, METH_VARARGS,
120
120
         "( index ) - set flagV and recalculate the knots (0: uniform, 1: endpoints, 2: bezier)"},
121
121
        {"getFlagV", ( PyCFunction ) CurNurb_getFlagV, METH_NOARGS,
122
122
         "( ) - get flagV of the knots"},
123
 
        {"setType", ( PyCFunction ) CurNurb_setType, METH_VARARGS,
 
123
        {"setType", ( PyCFunction ) CurNurb_oldsetType, METH_VARARGS,
124
124
         "( type ) - change the type of the curve (Poly: 0, Bezier: 1, NURBS: 4)"},
125
125
        {"getType", ( PyCFunction ) CurNurb_getType, METH_NOARGS,
126
126
         "( ) - get the type of the curve (Poly: 0, Bezier: 1, NURBS: 4)"},
156
156
        0
157
157
};
158
158
 
 
159
static PyGetSetDef BPy_CurNurb_getseters[] = {
 
160
        {"mat_index",
 
161
         (getter)CurNurb_getMatIndex, (setter)CurNurb_setMatIndex,
 
162
         "CurNurb's material index",
 
163
         NULL},
 
164
        {"points",
 
165
         (getter)CurNurb_getPoints, (setter)NULL,
 
166
         "The number of curve points",
 
167
         NULL},
 
168
        {"flagU",
 
169
         (getter)CurNurb_getFlagU, (setter)CurNurb_setFlagU,
 
170
         "The knot type in the U direction",
 
171
         NULL},
 
172
        {"flagV",
 
173
         (getter)CurNurb_getFlagV, (setter)CurNurb_setFlagV,
 
174
         "The knot type in the V direction",
 
175
         NULL},
 
176
        {"type",
 
177
         (getter)CurNurb_getType, (setter)CurNurb_setType,
 
178
         "The curve type (poly: bezier, or NURBS)",
 
179
         NULL},
 
180
        {"knotsU",
 
181
         (getter)CurNurb_getKnotsU, (setter)NULL,
 
182
         "The The knot vector in the U direction",
 
183
         NULL},
 
184
        {"knotsV",
 
185
         (getter)CurNurb_getKnotsV, (setter)NULL,
 
186
         "The The knot vector in the V direction",
 
187
         NULL},
159
188
 
 
189
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
190
};
160
191
 
161
192
/*
162
193
  Object Type definition
175
206
 
176
207
        /* Methods to implement standard operations */
177
208
 
178
 
        ( destructor ) CurNurb_dealloc, /*    destructor tp_dealloc; */
179
 
        0,                      /*    printfunc tp_print; */
180
 
        ( getattrfunc ) CurNurb_getAttr,        /*    getattrfunc tp_getattr; */
181
 
        ( setattrfunc ) CurNurb_setAttr,        /*    setattrfunc tp_setattr; */
 
209
        NULL,                                   /*    destructor tp_dealloc; */
 
210
        NULL,                                   /*    printfunc tp_print; */
 
211
        NULL,                                   /*    getattrfunc tp_getattr; */
 
212
        NULL,                                   /*    setattrfunc tp_setattr; */
182
213
        ( cmpfunc ) CurNurb_compare,    /*    cmpfunc tp_compare; */
183
214
        ( reprfunc ) CurNurb_repr,      /*    reprfunc tp_repr; */
184
215
 
225
256
  /*** Attribute descriptor and subclassing stuff ***/
226
257
        BPy_CurNurb_methods,    /*    struct PyMethodDef *tp_methods; */
227
258
        0,                      /*    struct PyMemberDef *tp_members; */
228
 
        0,                      /*    struct PyGetSetDef *tp_getset; */
 
259
        BPy_CurNurb_getseters,                  /*    struct PyGetSetDef *tp_getset; */
229
260
        0,                      /*    struct _typeobject *tp_base; */
230
261
        0,                      /*    PyObject *tp_dict; */
231
262
        0,                      /*    descrgetfunc tp_descr_get; */
247
278
        0
248
279
};
249
280
 
250
 
 
251
 
 
252
 
 
253
 
void CurNurb_dealloc( BPy_CurNurb * self )
254
 
{
255
 
        PyObject_DEL( self );
256
 
}
257
 
 
258
 
 
259
 
 
260
 
static PyObject *CurNurb_getAttr( BPy_CurNurb * self, char *name )
261
 
{
262
 
        PyObject *attr = Py_None;
263
 
 
264
 
        if( strcmp( name, "mat_index" ) == 0 )
265
 
                attr = PyInt_FromLong( self->nurb->mat_nr );
266
 
 
267
 
        else if( strcmp( name, "points" ) == 0 )
268
 
                attr = PyInt_FromLong( self->nurb->pntsu );
269
 
 
270
 
        else if( strcmp( name, "flagU" ) == 0 )
271
 
                attr = CurNurb_getFlagU( self );
272
 
 
273
 
        else if( strcmp( name, "flagV" ) == 0 )
274
 
                attr = CurNurb_getFlagV( self );
275
 
 
276
 
        else if( strcmp( name, "type" ) == 0 )
277
 
                attr = CurNurb_getType( self );
278
 
 
279
 
        else if( strcmp( name, "__members__" ) == 0 )
280
 
                attr = Py_BuildValue( "[s,s,s,s,s]", "mat_index", "points", "flagU", "flagV", "type" );
281
 
 
282
 
        if( !attr )
283
 
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
284
 
                                              "couldn't create PyObject" );
285
 
 
286
 
        /* member attribute found, return it */
287
 
        if( attr != Py_None )
288
 
                return attr;
289
 
 
290
 
        /* not an attribute, search the methods table */
291
 
        return Py_FindMethod( BPy_CurNurb_methods, ( PyObject * ) self, name );
292
 
}
293
 
 
294
 
 
295
 
/*
296
 
  setattr
297
 
*/
298
 
 
299
 
static int CurNurb_setAttr( BPy_CurNurb * self, char *name, PyObject * value )
300
 
{
301
 
        PyObject *valtuple;
302
 
        PyObject *error = NULL;
303
 
 
304
 
        /* make a tuple to pass to our type methods */
305
 
        valtuple = Py_BuildValue( "(O)", value );
306
 
 
307
 
        if( !valtuple )
308
 
                return EXPP_ReturnIntError( PyExc_MemoryError,
309
 
                                            "CurNurb.setAttr: cannot create pytuple" );
310
 
 
311
 
        if( strcmp( name, "mat_index" ) == 0 )
312
 
                error = CurNurb_setMatIndex( self, valtuple );
313
 
 
314
 
        else if( strcmp( name, "flagU" ) == 0 )
315
 
                error = CurNurb_setFlagU( self, valtuple );
316
 
 
317
 
        else if( strcmp( name, "flagV" ) == 0 )
318
 
                error = CurNurb_setFlagV( self, valtuple );
319
 
 
320
 
        else if( strcmp( name, "type" ) == 0 )
321
 
                error = CurNurb_setType( self, valtuple );
322
 
 
323
 
        else {                  /* error - no match for name */
324
 
                Py_DECREF( valtuple );
325
 
 
326
 
                if( ( strcmp( name, "ZZZZ" ) == 0 ) ||  /* user tried to change a */
327
 
                    ( strcmp( name, "ZZZZ" ) == 0 ) )   /* constant dict type ... */
328
 
                        return EXPP_ReturnIntError( PyExc_AttributeError,
329
 
                                                    "constant dictionary -- cannot be changed" );
330
 
                else
331
 
                        return EXPP_ReturnIntError( PyExc_KeyError,
332
 
                                                    "attribute not found" );
333
 
        }
334
 
 
335
 
 
336
 
        Py_DECREF( valtuple );  /* since it is not being returned */
337
 
        if( error != Py_None )
338
 
                return -1;
339
 
 
340
 
        Py_DECREF( Py_None );
341
 
        return 0;               /* normal exit */
342
 
}
343
 
 
344
281
/*
345
282
  compare
346
283
  in this case, we consider two CurNurbs equal, if they point to the same
405
342
 *
406
343
 *      Convert the curve using Blender's convertspline fonction
407
344
 */
408
 
static PyObject *CurNurb_setType( BPy_CurNurb * self, PyObject * args )
 
345
static int CurNurb_setType( BPy_CurNurb * self, PyObject * args )
409
346
{
410
 
        Nurb *nurb = self->nurb;
411
 
        short type;
412
 
 
413
 
        /* parameter type checking */
414
 
        if( !PyArg_ParseTuple( args, "h", &type ) )
415
 
                return EXPP_ReturnPyObjError
416
 
                        ( PyExc_TypeError, "expected integer argument" );
 
347
        PyObject* integer = PyNumber_Int( args );
 
348
        short value;
 
349
 
 
350
        if( !integer )
 
351
                return EXPP_ReturnIntError( PyExc_TypeError,
 
352
                                "expected integer argument" );
 
353
 
 
354
        value = ( short )PyInt_AS_LONG( integer );
 
355
        Py_DECREF( integer );
417
356
 
418
357
        /* parameter value checking */
419
 
        if (type != CU_POLY &&
420
 
                type != CU_BEZIER &&
421
 
                type != CU_NURBS)
422
 
                return EXPP_ReturnPyObjError
423
 
                         ( PyExc_ValueError, "expected integer argument" );
 
358
        if (value != CU_POLY && value != CU_BEZIER && value != CU_NURBS)
 
359
                return EXPP_ReturnIntError( PyExc_ValueError,
 
360
                                "expected integer argument" );
424
361
 
425
362
        /* convert and raise error if impossible */
426
 
        if (convertspline(type, nurb))
427
 
                return EXPP_ReturnPyObjError
428
 
                         ( PyExc_ValueError, "Conversion Impossible" );
429
 
 
430
 
        return EXPP_incr_ret( Py_None );
431
 
}
432
 
 
433
 
 
 
363
        if (convertspline(value, self->nurb))
 
364
                return EXPP_ReturnIntError( PyExc_ValueError,
 
365
                                "Conversion Impossible" );
 
366
 
 
367
        return 0;
 
368
}
 
369
 
 
370
/*
 
371
 * CurNurb_getKnotsU
 
372
 *
 
373
 * returns curve's knotsU in a tuple. Empty tuple is returned if curve
 
374
 * isn't Nurbs or it doesn't have knots in U
 
375
 */
 
376
 
 
377
static PyObject *CurNurb_getKnotsU( BPy_CurNurb * self )
 
378
{
 
379
        if(self->nurb->knotsu) {
 
380
                int len = KNOTSU(self->nurb);
 
381
                int i;
 
382
                PyObject *knotsu = PyTuple_New(len);
 
383
                if( !knotsu )
 
384
                        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
385
                                        "could not get CurNurb.knotsU attribute" );
 
386
 
 
387
                for(i = 0; i < len; ++i)
 
388
                        PyTuple_SetItem(knotsu, i,
 
389
                                        PyFloat_FromDouble(self->nurb->knotsu[i]));
 
390
 
 
391
                return knotsu;
 
392
        }
 
393
        return PyTuple_New(0);
 
394
}
 
395
 
 
396
/*
 
397
 * CurNurb_getKnotsV
 
398
 *
 
399
 * returns curve's knotsV in a tuple. Empty tuple is returned if curve doesn't have knots in V
 
400
 */
 
401
 
 
402
static PyObject *CurNurb_getKnotsV( BPy_CurNurb * self )
 
403
{
 
404
        if(self->nurb->knotsv) {
 
405
                int len = KNOTSV(self->nurb);
 
406
                int i;
 
407
                PyObject *knotsv = PyTuple_New(len);
 
408
                if( !knotsv )
 
409
                        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
410
                                        "could not get CurNurb.knotsV index" );
 
411
 
 
412
                for(i = 0; i < len; ++i)
 
413
                        PyTuple_SetItem(knotsv, i,
 
414
                                        PyFloat_FromDouble(self->nurb->knotsv[i] ));
 
415
        
 
416
                return knotsv;
 
417
        }
 
418
        return PyTuple_New(0);
 
419
}
 
420
 
 
421
static PyObject *CurNurb_getPoints( BPy_CurNurb * self )
 
422
{
 
423
        PyObject *attr = PyInt_FromLong( ( long ) self->nurb->pntsu );
 
424
 
 
425
        if( attr )
 
426
                return attr;
 
427
 
 
428
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
429
                        "could not get number of points" );
 
430
}
434
431
 
435
432
/*
436
433
 * CurNurb_append( point )
472
469
 
473
470
        /* if curve is empty, adjust type depending on input type */
474
471
        if (nurb->bezt==NULL && nurb->bp==NULL) {
475
 
                if (BezTriple_CheckPyObject( pyOb ))
 
472
                if (BPy_BezTriple_Check( pyOb ))
476
473
                        nurb->type |= CU_BEZIER;
477
474
                else if (PySequence_Check( pyOb ))
478
475
                        nurb->type |= CU_NURBS;
486
483
        if ((nurb->type & 7)==CU_BEZIER) {
487
484
                BezTriple *tmp;
488
485
 
489
 
                if( !BezTriple_CheckPyObject( pyOb ) )
 
486
                if( !BPy_BezTriple_Check( pyOb ) )
490
487
                        return( EXPP_ReturnPyObjError( PyExc_TypeError,
491
488
                                          "Expected a BezTriple\n" ) );
492
489
 
577
574
 
578
575
        }
579
576
 
580
 
        return ( EXPP_incr_ret( Py_None ) );
 
577
        Py_RETURN_NONE;
581
578
}
582
579
 
583
580
 
587
584
 *  set index into material list
588
585
 */
589
586
 
590
 
static PyObject *CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args )
 
587
static int CurNurb_setMatIndex( BPy_CurNurb * self, PyObject * args )
591
588
{
592
 
        int index;
593
 
 
594
 
        if( !PyArg_ParseTuple( args, "i", &( index ) ) )
595
 
                return ( EXPP_ReturnPyObjError
596
 
                         ( PyExc_AttributeError,
597
 
                           "expected integer argument" ) );
598
 
 
599
 
        /* fixme:  some range checking would be nice! */
600
 
        self->nurb->mat_nr = (short)index;
601
 
 
602
 
        Py_INCREF( Py_None );
603
 
        return Py_None;
 
589
        printf ("%d\n", self->nurb->mat_nr);
 
590
        return EXPP_setIValueRange( args, &self->nurb->mat_nr, 0, 15, 'h' );
604
591
}
605
592
 
606
593
/*
616
603
        if( index )
617
604
                return index;
618
605
 
619
 
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
620
 
                                        "could not get material index" ) );
 
606
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
607
                        "could not get material index" );
621
608
}
622
609
 
623
610
/*
646
633
 *    bit 0 controls CU_CYCLIC
647
634
 */
648
635
 
649
 
static PyObject *CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args )
 
636
static int CurNurb_setFlagU( BPy_CurNurb * self, PyObject * args )
650
637
{
651
 
        int flagu;
652
 
 
653
 
        if( !PyArg_ParseTuple( args, "i", &( flagu ) ) )
654
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
655
 
                                "expected integer argument in range [0,5]" );
656
 
 
657
 
        if( flagu < 0 || flagu > 5 )
658
 
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
659
 
                                "expected integer argument in range [0,5]" );
660
 
 
661
 
        if( self->nurb->flagu != flagu ) {
662
 
                self->nurb->flagu = (short)flagu;
 
638
        PyObject* integer = PyNumber_Int( args );
 
639
        short value;
 
640
 
 
641
        if( !integer )
 
642
                return EXPP_ReturnIntError( PyExc_TypeError,
 
643
                                "expected integer argument" );
 
644
 
 
645
        value = ( short )PyInt_AS_LONG( integer );
 
646
        Py_DECREF( integer );
 
647
 
 
648
        if( value < 0 || value > 5 )
 
649
                return EXPP_ReturnIntError( PyExc_ValueError,
 
650
                                "expected integer argument in range [0,5]" );
 
651
 
 
652
        if( self->nurb->flagu != value ) {
 
653
                self->nurb->flagu = (short)value;
663
654
                makeknots( self->nurb, 1, self->nurb->flagu >> 1 );
664
655
        }
665
656
 
666
 
        Py_INCREF( Py_None );
667
 
        return Py_None;
 
657
        return 0;
668
658
}
669
659
 
670
660
/*
692
682
 *  Possible values: 0 - uniform, 1 - endpoints, 2 - bezier
693
683
 */
694
684
 
695
 
static PyObject *CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args )
 
685
static int CurNurb_setFlagV( BPy_CurNurb * self, PyObject * args )
696
686
{
697
 
        int flagv;
698
 
 
699
 
        if( !PyArg_ParseTuple( args, "i", &( flagv ) ) )
700
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
701
 
                                "expected integer argument in range [0,5]" );
702
 
 
703
 
        if( flagv < 0 || flagv > 5 )
704
 
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
705
 
                                "expected integer argument in range [0,5]" );
706
 
 
707
 
        if( self->nurb->flagv != flagv ) {
708
 
                self->nurb->flagv = (short)flagv;
 
687
        PyObject* integer = PyNumber_Int( args );
 
688
        short value;
 
689
 
 
690
        if( !integer )
 
691
                return EXPP_ReturnIntError( PyExc_TypeError,
 
692
                                "expected integer argument" );
 
693
 
 
694
        value = ( short )PyInt_AS_LONG( integer );
 
695
        Py_DECREF( integer );
 
696
 
 
697
        if( value < 0 || value > 5 )
 
698
                return EXPP_ReturnIntError( PyExc_ValueError,
 
699
                                "expected integer argument in range [0,5]" );
 
700
 
 
701
        if( self->nurb->flagv != value ) {
 
702
                self->nurb->flagv = (short)value;
709
703
                makeknots( self->nurb, 2, self->nurb->flagv >> 1 );
710
704
        }
711
705
 
712
 
        Py_INCREF( Py_None );
713
 
        return Py_None;
 
706
        return 0;
714
707
}
715
708
 
716
709
/*
736
729
}
737
730
 
738
731
 
739
 
 
740
732
static PyObject *CurNurb_iterNext( BPy_CurNurb * self )
741
733
{
742
734
        PyObject *po;           /* return value */
812
804
        Nurb *nurb;
813
805
        int len;
814
806
 
815
 
        if( CurNurb_CheckPyObject( ( PyObject * ) inst ) ) {
 
807
        if( BPy_CurNurb_Check( ( PyObject * ) inst ) ) {
816
808
                nurb = ( ( BPy_CurNurb * ) inst )->nurb;
817
809
                len = nurb->pntsu;
818
810
                return len;
822
814
                                    "arg is not a BPy_CurNurb" );
823
815
}
824
816
 
825
 
 
826
817
/*
827
818
 * CurNurb_getPoint
828
819
 * returns the Nth point in a Nurb
877
868
        /* check index limits */
878
869
        if( index < 0 || index >= nurb->pntsu )
879
870
                return EXPP_ReturnIntError( PyExc_IndexError,
880
 
                                            "array assignment index out of range\n" );
 
871
                                            "array assignment index out of range" );
881
872
 
882
873
 
883
874
        /* branch by curve type */
884
875
        if ((nurb->type & 7)==CU_BEZIER) {      /* BEZIER */
885
876
                /* check parameter type */
886
 
                if( !BezTriple_CheckPyObject( pyOb ) )
 
877
                if( !BPy_BezTriple_Check( pyOb ) )
887
878
                        return EXPP_ReturnIntError( PyExc_TypeError,
888
 
                                                        "expected a BezTriple\n" );
 
879
                                                        "expected a BezTriple" );
889
880
 
890
881
                /* copy bezier in array */
891
882
                memcpy( nurb->bezt + index,
899
890
                /* check parameter type */
900
891
                if (!PySequence_Check( pyOb ))
901
892
                        return EXPP_ReturnIntError( PyExc_TypeError,
902
 
                                                        "expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
 
893
                                                        "expected a list of 4 (or optionally 5 if the curve is 3D) floats" );
903
894
 
904
895
                size = PySequence_Size( pyOb );
905
896
 
906
897
                /* check sequence size */
907
898
                if( size != 4 && size != 5 ) 
908
899
                        return EXPP_ReturnIntError( PyExc_TypeError,
909
 
                                                        "expected a list of 4 (or optionaly 5 if the curve is 3D) floats\n" );
 
900
                                                        "expected a list of 4 (or optionally 5 if the curve is 3D) floats" );
910
901
 
911
902
                /* copy x, y, z, w */
912
903
                for( i = 0; i < 4; ++i ) {
970
961
 
971
962
        } else                  /* something is horribly wrong */
972
963
                /* neither bp or bezt is set && pntsu != 0 */
973
 
                return ( EXPP_ReturnPyObjError( PyExc_SystemError,
974
 
                                                "inconsistant structure found" ) );
975
 
 
976
 
        return ( pyo );
977
 
}
978
 
 
979
 
 
980
 
int CurNurb_CheckPyObject( PyObject * py_obj )
981
 
{
982
 
        return ( py_obj->ob_type == &CurNurb_Type );
983
 
}
984
 
 
985
 
 
986
 
PyObject *CurNurb_Init( void )
987
 
{
988
 
        PyObject *submodule;
989
 
 
990
 
        CurNurb_Type.ob_type = &PyType_Type;
991
 
 
992
 
        submodule =
993
 
                Py_InitModule3( "Blender.CurNurb", M_CurNurb_methods,
994
 
                                M_CurNurb_doc );
995
 
        return ( submodule );
 
964
                return EXPP_ReturnPyObjError( PyExc_SystemError,
 
965
                                                "inconsistant structure found" );
 
966
 
 
967
        return pyo;
996
968
}
997
969
 
998
970
/*
1006
978
        Nurb *nurb = self->nurb;
1007
979
        int npoints = 0;
1008
980
 
1009
 
        if( ! self->nurb ){  /* bail on error */
1010
 
                printf("\n no Nurb in this CurNurb");
1011
 
                Py_RETURN_NONE;
1012
 
        }
 
981
        if( !self->nurb )
 
982
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
983
                                "no Nurb in this CurNurb");
1013
984
 
1014
985
        printf(" type: %d, mat_nr: %d hide: %d flag: %d",
1015
986
                   nurb->type, nurb->mat_nr, nurb->hide, nurb->flag);
1076
1047
        Py_RETURN_NONE;
1077
1048
}
1078
1049
 
1079
 
PyObject *CurNurb_switchDirection( BPy_CurNurb * self ) {
1080
 
        Nurb *nurb = self->nurb;
1081
 
        if( ! self->nurb ){  /* bail on error */
1082
 
                printf("\n no Nurb in this CurNurb");
1083
 
                Py_RETURN_NONE;
1084
 
        }
 
1050
PyObject *CurNurb_switchDirection( BPy_CurNurb * self )
 
1051
{
 
1052
        if( !self->nurb )
 
1053
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1054
                                "no Nurb in this CurNurb");
1085
1055
        
1086
 
        switchdirectionNurb( nurb );
 
1056
        switchdirectionNurb( self->nurb );
1087
1057
        
1088
1058
        Py_RETURN_NONE;
1089
1059
}
 
1060
 
 
1061
PyObject *CurNurb_Init( void )
 
1062
{
 
1063
        if( PyType_Ready( &CurNurb_Type ) < 0)
 
1064
                return NULL;
 
1065
 
 
1066
        return Py_InitModule3( "Blender.CurNurb", M_CurNurb_methods,
 
1067
                                M_CurNurb_doc );
 
1068
}
 
1069
 
 
1070
/* #####DEPRECATED###### */
 
1071
 
 
1072
static PyObject *CurNurb_oldsetType( BPy_CurNurb * self, PyObject * args )
 
1073
{
 
1074
        return EXPP_setterWrapper( (void *)self, args,
 
1075
                        (setter)CurNurb_setType );
 
1076
}
 
1077
 
 
1078
static PyObject *CurNurb_oldsetMatIndex( BPy_CurNurb * self, PyObject * args )
 
1079
{
 
1080
        return EXPP_setterWrapper( (void *)self, args,
 
1081
                        (setter)CurNurb_setMatIndex );
 
1082
}
 
1083
 
 
1084
static PyObject *CurNurb_oldsetFlagU( BPy_CurNurb * self, PyObject * args )
 
1085
{
 
1086
        return EXPP_setterWrapper( (void *)self, args,
 
1087
                        (setter)CurNurb_setFlagU );
 
1088
}
 
1089
 
 
1090
static PyObject *CurNurb_oldsetFlagV( BPy_CurNurb * self, PyObject * args )
 
1091
{
 
1092
        return EXPP_setterWrapper( (void *)self, args,
 
1093
                        (setter)CurNurb_setFlagV );
 
1094
}