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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/BezTriple.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: BezTriple.c,v 1.8 2004/04/07 22:42:02 stiv Exp $
 
2
 * $Id: BezTriple.c,v 1.11 2005/06/13 19:15:01 stiv 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): Jacques Guignot
 
27
 * Contributor(s): Jacques Guignot RIP 2005,
 
28
 *    Stephen Swaney
28
29
 *
29
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
31
 */
39
40
#include <BKE_library.h>
40
41
#include <BLI_blenlib.h>
41
42
#include <DNA_ipo_types.h>
 
43
#include <MEM_guardedalloc.h>
42
44
 
43
45
#include "constant.h"
44
46
#include "gen_utils.h"
45
 
#include "modules.h"
46
 
 
47
 
/*****************************************************************************/
48
 
/* Python API function prototypes for the BezTriple module.                        */
49
 
/*****************************************************************************/
50
 
static PyObject *M_BezTriple_New (PyObject * self, PyObject * args);
51
 
static PyObject *M_BezTriple_Get (PyObject * self, PyObject * args);
52
 
 
53
 
/*****************************************************************************/
54
 
/* Python C_BezTriple instance methods declarations:                            */
55
 
/*****************************************************************************/
56
 
static PyObject *BezTriple_setPoints (C_BezTriple * self, PyObject * args);
57
 
static PyObject *BezTriple_getPoints (C_BezTriple * self);
58
 
static PyObject *BezTriple_getTriple (C_BezTriple * self);
59
 
 
60
 
/*****************************************************************************/
61
 
/* Python BezTriple_Type callback function prototypes:                          */
62
 
/*****************************************************************************/
63
 
static void BezTripleDeAlloc (C_BezTriple * self);
64
 
static int BezTripleSetAttr (C_BezTriple * self, char *name, PyObject * v);
65
 
static PyObject *BezTripleGetAttr (C_BezTriple * self, char *name);
66
 
static PyObject *BezTripleRepr (C_BezTriple * self);
67
 
 
68
 
/*****************************************************************************/
69
 
/* Python method structure definition for Blender.BezTriple module:             */
70
 
/*****************************************************************************/
 
47
 
 
48
 
 
49
/***************************************************************************
 
50
  Python API function prototypes for the BezTriple module.                  
 
51
***************************************************************************/
 
52
static PyObject *M_BezTriple_New( PyObject * self, PyObject * args );
 
53
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args );
 
54
 
 
55
/*************************************
 
56
 Doc strings for the BezTriple module
 
57
*************************************/
 
58
 
 
59
static char M_BezTriple_doc[] = "The Blender BezTriple module\n";
 
60
 
 
61
/****************************************************************************
 
62
  Python BPy_BezTriple instance methods declarations:                        
 
63
****************************************************************************/
 
64
static PyObject *BezTriple_setPoints( BPy_BezTriple * self, PyObject * args );
 
65
static PyObject *BezTriple_getPoints( BPy_BezTriple * self );
 
66
static PyObject *BezTriple_getTriple( BPy_BezTriple * self );
 
67
 
 
68
/****************************************************************************
 
69
 Python BezTriple_Type callback function prototypes:                      
 
70
*****************************************************************************/
 
71
static void BezTripleDeAlloc( BPy_BezTriple * self );
 
72
static int BezTripleSetAttr( BPy_BezTriple * self, char *name, PyObject * v );
 
73
static PyObject *BezTripleGetAttr( BPy_BezTriple * self, char *name );
 
74
static PyObject *BezTripleRepr( BPy_BezTriple * self );
 
75
static PyObject *BezTriple_Str( BPy_BezTriple * self );
 
76
 
 
77
/****************************************************************************
 
78
 Python method structure definition for Blender.BezTriple module:          
 
79
****************************************************************************/
71
80
 
72
81
struct PyMethodDef M_BezTriple_methods[] = {
73
 
  {"New", (PyCFunction) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS, 0},
74
 
  {"Get", M_BezTriple_Get, METH_VARARGS, 0},
75
 
  {"get", M_BezTriple_Get, METH_VARARGS, 0},
76
 
  {NULL, NULL, 0, NULL}
77
 
};
78
 
 
79
 
/*****************************************************************************/
80
 
/* Python C_BezTriple methods table:                                            */
81
 
/*****************************************************************************/
82
 
static PyMethodDef C_BezTriple_methods[] = {
83
 
  /* name, method, flags, doc */
84
 
  {"setPoints", (PyCFunction) BezTriple_setPoints, METH_VARARGS,
85
 
   "(str) - Change BezTriple point coordinates"},
86
 
  {"getPoints", (PyCFunction) BezTriple_getPoints, METH_NOARGS,
87
 
   "() - return BezTriple knot point x and y coordinates"},
88
 
  {"getTriple", (PyCFunction) BezTriple_getTriple, METH_NOARGS,
89
 
   "() - return list of 3 floating point triplets.  order is H1, knot, H2"},
90
 
  {NULL, NULL, 0, NULL}
91
 
};
92
 
 
93
 
 
94
 
/*****************************************************************************/
95
 
/* Python BezTriple_Type structure definition:                                  */
 
82
        {"New", ( PyCFunction ) M_BezTriple_New, METH_VARARGS | METH_KEYWORDS,
 
83
         0},
 
84
/*      {"New", ( PyCFunction ) M_BezTriple_New, METH_O, 0}, */
 
85
        {"Get", M_BezTriple_Get, METH_VARARGS, 0},
 
86
        {"get", M_BezTriple_Get, METH_VARARGS, 0},
 
87
        {NULL, NULL, 0, NULL}
 
88
};
 
89
 
 
90
/*****************************************************************************/
 
91
/* Python BPy_BezTriple methods table:                                        */
 
92
/*****************************************************************************/
 
93
static PyMethodDef BPy_BezTriple_methods[] = {
 
94
        /* name, method, flags, doc */
 
95
        {"setPoints", ( PyCFunction ) BezTriple_setPoints, METH_VARARGS,
 
96
         "(str) - Change BezTriple point coordinates"},
 
97
        {"getPoints", ( PyCFunction ) BezTriple_getPoints, METH_NOARGS,
 
98
         "() - return BezTriple knot point x and y coordinates"},
 
99
        {"getTriple", ( PyCFunction ) BezTriple_getTriple, METH_NOARGS,
 
100
         "() - return list of 3 floating point triplets.  order is H1, knot, H2"},
 
101
        {NULL, NULL, 0, NULL}
 
102
};
 
103
 
 
104
 
 
105
/*****************************************************************************/
 
106
/* Python BezTriple_Type structure definition:                              */
96
107
/*****************************************************************************/
97
108
PyTypeObject BezTriple_Type = {
98
 
  PyObject_HEAD_INIT (NULL) 0,  /* ob_size */
99
 
  "BezTriple",                  /* tp_name */
100
 
  sizeof (C_BezTriple),         /* tp_basicsize */
101
 
  0,                            /* tp_itemsize */
102
 
  /* methods */
103
 
  (destructor) BezTripleDeAlloc,        /* tp_dealloc */
104
 
  0,                            /* tp_print */
105
 
  (getattrfunc) BezTripleGetAttr,       /* tp_getattr */
106
 
  (setattrfunc) BezTripleSetAttr,       /* tp_setattr */
107
 
  0,                            /* tp_compare */
108
 
  (reprfunc) BezTripleRepr,     /* tp_repr */
109
 
  0,                            /* tp_as_number */
110
 
  0,                            /* tp_as_sequence */
111
 
  0,                            /* tp_as_mapping */
112
 
  0,                            /* tp_as_hash */
113
 
  0, 0, 0, 0, 0, 0,
114
 
  0,                            /* tp_doc */
115
 
  0, 0, 0, 0, 0, 0,
116
 
  C_BezTriple_methods,          /* tp_methods */
117
 
  0,                            /* tp_members */
118
 
  0,                            /* tm_getset */
119
 
  0
 
109
        PyObject_HEAD_INIT( NULL )      /*    required python macro            */
 
110
                0,              /* ob_size */
 
111
        "BezTriple",            /* tp_name */
 
112
        sizeof( BPy_BezTriple ),        /* tp_basicsize */
 
113
        0,                      /* tp_itemsize */
 
114
        /* methods */
 
115
        ( destructor ) BezTripleDeAlloc,        /* tp_dealloc */
 
116
        0,                      /* tp_print */
 
117
        ( getattrfunc ) BezTripleGetAttr,       /* tp_getattr */
 
118
        ( setattrfunc ) BezTripleSetAttr,       /* tp_setattr */
 
119
        0,                      /* tp_compare */
 
120
        ( reprfunc ) BezTripleRepr,     /* tp_repr */
 
121
        0,                      /* tp_as_number */
 
122
        0,                      /* tp_as_sequence */
 
123
        0,                      /* tp_as_mapping */
 
124
        0,                      /* tp_as_hash */
 
125
        0,                      /* tp_call */
 
126
        0,  /*  ( reprfunc) BezTriple_Str,       tp_str */
 
127
        0,                      /* tp_getattro */
 
128
        0,                      /* tp_setattro */
 
129
        0,                      /* tp_as_buffer */
 
130
        0,                      /* tp_flags */
 
131
        0,                      /* tp_doc */
 
132
        0, 0, 0, 0, 0, 0,
 
133
        BPy_BezTriple_methods,  /* tp_methods */
 
134
        0,                      /* tp_members */
 
135
        0,                      /* tm_getset */
 
136
        0
120
137
};
121
138
 
122
139
 
123
 
/*****************************************************************************/
124
 
/* Function:              M_BezTriple_New                                          */
125
 
/* Python equivalent:     Blender.BezTriple.New                                    */
126
 
/*****************************************************************************/
127
 
static PyObject *
128
 
M_BezTriple_New (PyObject * self, PyObject * args)
129
 
{
130
 
  return 0;
131
 
}
132
 
 
133
 
/*****************************************************************************/
134
 
/* Function:              M_BezTriple_Get                                       */
135
 
/* Python equivalent:     Blender.BezTriple.Get                                 */
136
 
/* Description:           Receives a string and returns the ipo data obj  */
137
 
/*                        whose name matches the string.  If no argument is  */
138
 
/*                        passed in, a list of all ipo data names in the  */
139
 
/*                        current scene is returned.                         */
140
 
/*****************************************************************************/
141
 
static PyObject *
142
 
M_BezTriple_Get (PyObject * self, PyObject * args)
143
 
{
144
 
  return 0;
145
 
}
146
 
 
147
 
/*****************************************************************************/
148
 
/* Function:    BezTripleDeAlloc                                                   */
149
 
/* Description: This is a callback function for the C_BezTriple type. It is        */
150
 
/*              the destructor function.                                     */
151
 
/*****************************************************************************/
152
 
static void
153
 
BezTripleDeAlloc (C_BezTriple * self)
154
 
{
155
 
  PyObject_DEL (self);
156
 
}
157
 
 
158
 
static PyObject *
159
 
BezTriple_getPoints (C_BezTriple * self)
160
 
{
161
 
  struct BezTriple *bezt = self->beztriple;
162
 
  PyObject *l = PyList_New (0);
163
 
  int i;
164
 
  for (i = 0; i < 2; i++)
165
 
    {
166
 
      PyList_Append (l, PyFloat_FromDouble (bezt->vec[1][i]));
167
 
    }
168
 
  return l;
 
140
/****************************************************************************
 
141
 Function:              M_BezTriple_New                                   
 
142
 Python equivalent:     Blender.BezTriple.New                             
 
143
****************************************************************************/
 
144
 
 
145
static PyObject *M_BezTriple_New( PyObject* self, PyObject * args )
 
146
{
 
147
        PyObject* in_args = NULL;
 
148
 
 
149
        if( !PyArg_ParseTuple( args, "|O", &in_args) ) {
 
150
                return( EXPP_ReturnPyObjError
 
151
                                ( PyExc_AttributeError,
 
152
                                  "expected sequence of 3 or 9 floats or nothing"));
 
153
        }
 
154
 
 
155
        if( !in_args ) {
 
156
                in_args = Py_BuildValue( "(fff)", 0.0, 0.0, 0.0 );
 
157
        }
 
158
                
 
159
        return newBezTriple( in_args );
 
160
}
 
161
 
 
162
/****************************************************************************
 
163
 Function:              M_BezTriple_Get                                   
 
164
 Python equivalent:     Blender.BezTriple.Get                             
 
165
 Description:           Receives a string and returns the ipo data obj  
 
166
                        whose name matches the string.  If no argument is  
 
167
                        passed in, a list of all ipo data names in the  
 
168
                        current scene is returned.                         
 
169
****************************************************************************/
 
170
static PyObject *M_BezTriple_Get( PyObject * self, PyObject * args )
 
171
{
 
172
        return 0;
 
173
}
 
174
 
 
175
/****************************************************************************
 
176
 Function:    BezTripleDeAlloc                                            
 
177
 Description: This is a callback function for the BPy_BezTriple type. It is  
 
178
              the destructor function.                                     
 
179
****************************************************************************/
 
180
static void BezTripleDeAlloc( BPy_BezTriple * self )
 
181
{
 
182
 
 
183
        if( self->own_memory)
 
184
                MEM_freeN( self->beztriple );
 
185
        
 
186
        PyObject_DEL( self );
 
187
}
 
188
 
 
189
static PyObject *BezTriple_getPoints( BPy_BezTriple * self )
 
190
{
 
191
        struct BezTriple *bezt = self->beztriple;
 
192
        PyObject *l = PyList_New( 0 );
 
193
        int i;
 
194
        for( i = 0; i < 2; i++ ) {
 
195
                PyList_Append( l, PyFloat_FromDouble( bezt->vec[1][i] ) );
 
196
        }
 
197
        return l;
169
198
}
170
199
 
171
200
 
178
207
 *  each point consists of a list of x,y,z float values.
179
208
 */
180
209
 
181
 
static PyObject *
182
 
BezTriple_getTriple (C_BezTriple * self)
183
 
{
184
 
  int i;
185
 
  struct BezTriple *bezt = self->beztriple;
186
 
  PyObject *retlist = PyList_New (0);
187
 
  PyObject *point;
188
 
 
189
 
  for (i = 0; i < 3; i++)
190
 
    {
191
 
      point = Py_BuildValue ("[fff]",
192
 
                             bezt->vec[i][0],
193
 
                             bezt->vec[i][1], bezt->vec[i][2]);
194
 
 
195
 
      PyList_Append (retlist, point);
196
 
    }
197
 
 
198
 
  return retlist;
199
 
}
200
 
 
201
 
 
202
 
static PyObject *
203
 
BezTriple_setPoints (C_BezTriple * self, PyObject * args)
204
 
{
205
 
 
206
 
  int i;
207
 
  struct BezTriple *bezt = self->beztriple;
208
 
  PyObject *popo = 0;
209
 
 
210
 
  if (!PyArg_ParseTuple (args, "O", &popo))
211
 
    return (EXPP_ReturnPyObjError
212
 
            (PyExc_TypeError, "expected sequence argument"));
213
 
 
214
 
  if (PySequence_Check (popo) == 0)
215
 
    {
216
 
      puts ("error in BezTriple_setPoints - expected sequence");
217
 
      Py_INCREF (Py_None);
218
 
      return Py_None;
219
 
    }
220
 
 
221
 
  {
222
 
    /*
223
 
       some debug stuff 
224
 
       this will become an overloaded args check
225
 
     */
226
 
    int size = PySequence_Size (popo);
227
 
    printf ("\n dbg: sequence size is %d\n", size);
228
 
  }
229
 
 
230
 
  for (i = 0; i < 2; i++)
231
 
    {
232
 
      PyObject *o = PySequence_GetItem (popo, i);
233
 
      if (!o)
234
 
        printf ("\n bad o. o no!\n");
235
 
 
236
 
      /*   bezt->vec[1][i] = PyFloat_AsDouble (PyTuple_GetItem (popo, i)); */
237
 
      bezt->vec[1][i] = PyFloat_AsDouble (o);
238
 
      bezt->vec[0][i] = bezt->vec[1][i] - 1;
239
 
      bezt->vec[2][i] = bezt->vec[1][i] + 1;
240
 
    }
241
 
 
242
 
  /* experimental fussing with handles - ipo.c: calchandles_ipocurve */
243
 
  if (bezt->vec[0][0] > bezt->vec[1][0])
244
 
    bezt->vec[0][0] = bezt->vec[1][0];
245
 
 
246
 
  if (bezt->vec[2][0] < bezt->vec[1][0])
247
 
    bezt->vec[2][0] = bezt->vec[1][0];
248
 
 
249
 
  Py_INCREF (Py_None);
250
 
  return Py_None;
251
 
}
252
 
 
253
 
 
254
 
/*****************************************************************************/
255
 
/* Function:    BezTripleGetAttr                                                   */
256
 
/* Description: This is a callback function for the C_BezTriple type. It is        */
257
 
/*              the function that accesses C_BezTriple "member variables" and      */
258
 
/*              methods.                                                     */
259
 
/*****************************************************************************/
260
 
static PyObject *
261
 
BezTripleGetAttr (C_BezTriple * self, char *name)
262
 
{
263
 
  if (strcmp (name, "pt") == 0)
264
 
    return BezTriple_getPoints (self);
265
 
  else if (strcmp (name, "vec") == 0)
266
 
    return BezTriple_getTriple (self);
267
 
 
268
 
  /* look for default methods */
269
 
  return Py_FindMethod (C_BezTriple_methods, (PyObject *) self, name);
270
 
}
271
 
 
272
 
/*****************************************************************************/
273
 
/* Function:    BezTripleSetAttr                                                */
274
 
/* Description: This is a callback function for the C_BezTriple type. It is the */
275
 
/*              function that sets BezTriple Data attributes (member variables).*/
276
 
/*****************************************************************************/
277
 
static int
278
 
BezTripleSetAttr (C_BezTriple * self, char *name, PyObject * value)
 
210
static PyObject *BezTriple_getTriple( BPy_BezTriple * self )
 
211
{
 
212
        int i;
 
213
        struct BezTriple *bezt = self->beztriple;
 
214
        PyObject *retlist = PyList_New( 0 );
 
215
        PyObject *point;
 
216
 
 
217
        for( i = 0; i < 3; i++ ) {
 
218
                point = Py_BuildValue( "[fff]",
 
219
                                       bezt->vec[i][0],
 
220
                                       bezt->vec[i][1], bezt->vec[i][2] );
 
221
 
 
222
                PyList_Append( retlist, point );
 
223
        }
 
224
 
 
225
        return retlist;
 
226
}
 
227
 
 
228
 
 
229
static PyObject *BezTriple_setPoints( BPy_BezTriple * self, PyObject * args )
 
230
{
 
231
 
 
232
        int i;
 
233
        struct BezTriple *bezt = self->beztriple;
 
234
        PyObject *popo = 0;
 
235
 
 
236
        if( !PyArg_ParseTuple( args, "O", &popo ) )
 
237
                return ( EXPP_ReturnPyObjError
 
238
                         ( PyExc_TypeError, "expected sequence argument" ) );
 
239
 
 
240
        if( PySequence_Check( popo ) == 0 ) {
 
241
                puts( "error in BezTriple_setPoints - expected sequence" );
 
242
                Py_INCREF( Py_None );
 
243
                return Py_None;
 
244
        }
 
245
 
 
246
        {
 
247
                /*
 
248
                   some debug stuff 
 
249
                   this will become an overloaded args check
 
250
                 */
 
251
                int size = PySequence_Size( popo );
 
252
                printf( "\n dbg: sequence size is %d\n", size );
 
253
        }
 
254
 
 
255
        for( i = 0; i < 2; i++ ) {
 
256
                PyObject *o = PySequence_GetItem( popo, i );
 
257
                if( !o )
 
258
                        printf( "\n bad o. o no!\n" );
 
259
 
 
260
                /*   bezt->vec[1][i] = PyFloat_AsDouble (PyTuple_GetItem (popo, i)); */
 
261
                bezt->vec[1][i] = PyFloat_AsDouble( o );
 
262
                bezt->vec[0][i] = bezt->vec[1][i] - 1;
 
263
                bezt->vec[2][i] = bezt->vec[1][i] + 1;
 
264
        }
 
265
 
 
266
        /* experimental fussing with handles - ipo.c: calchandles_ipocurve */
 
267
        if( bezt->vec[0][0] > bezt->vec[1][0] )
 
268
                bezt->vec[0][0] = bezt->vec[1][0];
 
269
 
 
270
        if( bezt->vec[2][0] < bezt->vec[1][0] )
 
271
                bezt->vec[2][0] = bezt->vec[1][0];
 
272
 
 
273
        Py_INCREF( Py_None );
 
274
        return Py_None;
 
275
}
 
276
 
 
277
 
 
278
/*****************************************************************************/
 
279
/* Function:    BezTripleGetAttr                                            */
 
280
/* Description: This is a callback function for the BPy_BezTriple type. It   */
 
281
/*              taccesses BPy_BezTriple "member variables" and    methods.    */
 
282
/*****************************************************************************/
 
283
static PyObject *BezTripleGetAttr( BPy_BezTriple * self, char *name )
 
284
{
 
285
        if( strcmp( name, "pt" ) == 0 )
 
286
                return BezTriple_getPoints( self );
 
287
        else if( strcmp( name, "vec" ) == 0 )
 
288
                return BezTriple_getTriple( self );
 
289
        else if( strcmp( name, "tilt" ) == 0 )
 
290
                return PyFloat_FromDouble(self->beztriple->alfa);
 
291
        else if( strcmp( name, "__members__" ) == 0 )
 
292
                return Py_BuildValue( "[s,s,s]", "pt", "vec", "tilt" );
 
293
 
 
294
        /* look for default methods */
 
295
        return Py_FindMethod( BPy_BezTriple_methods, ( PyObject * ) self, name );
 
296
}
 
297
 
 
298
/*****************************************************************************/
 
299
/* Function:    BezTripleSetAttr                                            */
 
300
/* Description: This is a callback function for the BPy_BezTriple type. It */
 
301
/*               sets BezTriple Data attributes (member variables).  */
 
302
/*****************************************************************************/
 
303
static int BezTripleSetAttr( BPy_BezTriple * self, char *name, PyObject * value )
279
304
{
280
305
#if 0
281
 
  /*
282
 
     this does not work at the moment:  Wed Apr  7  2004
283
 
     when the necessary code to make pt act like a sequence is
284
 
     available, it will be reenabled
285
 
   */
286
 
 
287
 
  if (strcmp (name, "pt") == 0)
288
 
    BezTriple_setPoints (self, value);
289
 
 
290
 
  return 0;                     /* normal exit */
 
306
        /*
 
307
           this does not work at the moment:  Wed Apr  7  2004
 
308
           when the necessary code to make pt act like a sequence is
 
309
           available, it will be reenabled
 
310
         */
 
311
 
 
312
        if( strcmp( name, "pt" ) == 0 )
 
313
                BezTriple_setPoints( self, value );
 
314
 
 
315
        return 0;               /* normal exit */
291
316
#endif
292
 
 
293
 
  return (EXPP_ReturnIntError (PyExc_AttributeError,
294
 
                               "cannot set a read-only attribute"));
 
317
        if( strcmp( name, "tilt" ) == 0 ) {
 
318
                if (!PyFloat_Check( value ) )
 
319
                        return EXPP_ReturnIntError( PyExc_TypeError, "expected a float" );
 
320
 
 
321
                self->beztriple->alfa = (float)PyFloat_AsDouble( value );
 
322
                return 0;
 
323
        }
 
324
 
 
325
        return ( EXPP_ReturnIntError( PyExc_AttributeError,
 
326
                                      "cannot set a read-only attribute" ) );
295
327
}
296
328
 
297
329
/*****************************************************************************/
298
330
/* Function:    BezTripleRepr                                                */
299
 
/* Description: This is a callback function for the C_BezTriple type. It     */
 
331
/* Description: This is a callback function for the BPy_BezTriple type. It     */
300
332
/*              builds a meaninful string to represent  BezTriple objects.   */
301
333
/*****************************************************************************/
302
 
static PyObject *
303
 
BezTripleRepr (C_BezTriple * self)
304
 
{
305
 
  /*      float vec[3][3];
306
 
     float alfa;
307
 
     short s[3][2];
308
 
     short h1, h2;
309
 
     char f1, f2, f3, hide;
310
 
   */
311
 
  char str[1000];
312
 
  sprintf (str,
313
 
           "BezTriple %f %f %f %f %f %f %f %f %f %f\n %d %d %d %d %d %d %d %d %d %d %d %d\n",
314
 
           self->beztriple->vec[0][0], self->beztriple->vec[0][1],
315
 
           self->beztriple->vec[0][2], self->beztriple->vec[1][0],
316
 
           self->beztriple->vec[1][1], self->beztriple->vec[1][2],
317
 
           self->beztriple->vec[2][0], self->beztriple->vec[2][1],
318
 
           self->beztriple->vec[2][2], self->beztriple->alfa,
319
 
           self->beztriple->s[0][0], self->beztriple->s[0][1],
320
 
           self->beztriple->s[1][0], self->beztriple->s[1][1],
321
 
           self->beztriple->s[2][0], self->beztriple->s[1][1],
322
 
           self->beztriple->h1, self->beztriple->h2, self->beztriple->f1,
323
 
           self->beztriple->f2, self->beztriple->f3, self->beztriple->hide);
324
 
  return PyString_FromString (str);
 
334
static PyObject *BezTripleRepr( BPy_BezTriple * self )
 
335
{
 
336
        /*      float vec[3][3];
 
337
           float alfa;
 
338
           short s[3][2];
 
339
           short h1, h2;
 
340
           char f1, f2, f3, hide;
 
341
         */
 
342
        char str[1000];
 
343
        sprintf( str,
 
344
                 "BezTriple %f %f %f %f %f %f %f %f %f %f\n %d %d %d %d %d %d %d %d %d %d %d %d\n",
 
345
                 self->beztriple->vec[0][0], self->beztriple->vec[0][1],
 
346
                 self->beztriple->vec[0][2], self->beztriple->vec[1][0],
 
347
                 self->beztriple->vec[1][1], self->beztriple->vec[1][2],
 
348
                 self->beztriple->vec[2][0], self->beztriple->vec[2][1],
 
349
                 self->beztriple->vec[2][2], self->beztriple->alfa,
 
350
                 self->beztriple->s[0][0], self->beztriple->s[0][1],
 
351
                 self->beztriple->s[1][0], self->beztriple->s[1][1],
 
352
                 self->beztriple->s[2][0], self->beztriple->s[1][1],
 
353
                 self->beztriple->h1, self->beztriple->h2, self->beztriple->f1,
 
354
                 self->beztriple->f2, self->beztriple->f3,
 
355
                 self->beztriple->hide );
 
356
        return PyString_FromString( str );
 
357
}
 
358
 
 
359
 
 
360
/*
 
361
 BezTriple_Str
 
362
 display object as string.
 
363
 equivalent to python str(o)
 
364
*/
 
365
 
 
366
static PyObject *BezTriple_Str( BPy_BezTriple * self )
 
367
{
 
368
        BezTriple *p = self->beztriple;
 
369
 
 
370
/* fixme: */
 
371
        return PyString_FromFormat(
 
372
                 "BezTriple (%f %f %f) (%f %f %f) (%f %f %f) alpha %f\n (%d %d) (%d %d) (%d %d) h1:%d h2:%d f1:%d f2:%d f3:%d hide:%d",
 
373
                 p->vec[0][0], p->vec[0][1],  p->vec[0][2], 
 
374
                 p->vec[1][0],  p->vec[1][1], p->vec[1][2],
 
375
                 p->vec[2][0], p->vec[2][1],  p->vec[2][2],
 
376
                 p->alfa,
 
377
                 p->s[0][0], p->s[0][1],
 
378
                 p->s[1][0], p->s[1][1],
 
379
                 p->s[2][0], p->s[1][1],
 
380
                 p->h1, p->h2, p->f1,
 
381
                 p->f2, p->f3,
 
382
                 p->hide );
 
383
 
 
384
}
 
385
 
 
386
 
 
387
/*
 
388
  BezTriple_Init
 
389
*/
 
390
 
 
391
PyObject *BezTriple_Init( void )
 
392
{
 
393
        PyObject *submodule;
 
394
 
 
395
        BezTriple_Type.ob_type = &PyType_Type;
 
396
 
 
397
        submodule = Py_InitModule3( "Blender.BezTriple",
 
398
                                                                M_BezTriple_methods,
 
399
                                                                M_BezTriple_doc );
 
400
 
 
401
        return submodule;
325
402
}
326
403
 
327
404
/* Three Python BezTriple_Type helper functions needed by the Object module: */
328
405
 
329
 
/*****************************************************************************/
330
 
/* Function:    BezTriple_CreatePyObject                                           */
331
 
/* Description: This function will create a new C_BezTriple from an existing       */
332
 
/*              Blender ipo structure.                                       */
333
 
/*****************************************************************************/
334
 
PyObject *
335
 
BezTriple_CreatePyObject (BezTriple * bzt)
 
406
/****************************************************************************
 
407
 Function:    BezTriple_CreatePyObject                                    
 
408
 Description: This function will create a new BPy_BezTriple from an existing 
 
409
              Blender ipo structure.                                       
 
410
****************************************************************************/
 
411
PyObject *BezTriple_CreatePyObject( BezTriple * bzt )
336
412
{
337
 
  C_BezTriple *pybeztriple;
338
 
 
339
 
  pybeztriple = (C_BezTriple *) PyObject_NEW (C_BezTriple, &BezTriple_Type);
340
 
 
341
 
  if (!pybeztriple)
342
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
343
 
                                  "couldn't create C_BezTriple object");
344
 
 
345
 
  pybeztriple->beztriple = bzt;
346
 
 
347
 
  return (PyObject *) pybeztriple;
 
413
        BPy_BezTriple *pybeztriple;
 
414
 
 
415
        pybeztriple =
 
416
                ( BPy_BezTriple * ) PyObject_NEW( BPy_BezTriple, &BezTriple_Type );
 
417
 
 
418
        if( !pybeztriple )
 
419
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
420
                                              "couldn't create BPy_BezTriple object" );
 
421
 
 
422
        pybeztriple->beztriple = bzt;
 
423
 
 
424
        return ( PyObject * ) pybeztriple;
348
425
}
349
426
 
 
427
 
350
428
/*****************************************************************************/
351
 
/* Function:    BezTriple_CheckPyObject                                            */
 
429
/* Function:    BezTriple_CheckPyObject                                     */
352
430
/* Description: This function returns true when the given PyObject is of the */
353
 
/*              type BezTriple. Otherwise it will return false.                    */
 
431
/*              type BezTriple. Otherwise it will return false.             */
354
432
/*****************************************************************************/
355
 
int
356
 
BezTriple_CheckPyObject (PyObject * pyobj)
 
433
int BezTriple_CheckPyObject( PyObject * pyobj )
357
434
{
358
 
  return (pyobj->ob_type == &BezTriple_Type);
 
435
        return ( pyobj->ob_type == &BezTriple_Type );
359
436
}
360
437
 
361
438
/*****************************************************************************/
362
 
/* Function:    BezTriple_FromPyObject                                             */
363
 
/* Description: This function returns the Blender beztriple from the given         */
 
439
/* Function:    BezTriple_FromPyObject                                      */
 
440
/* Description: This function returns the Blender beztriple from the given   */
364
441
/*              PyObject.                                                    */
365
442
/*****************************************************************************/
366
 
BezTriple *
367
 
BezTriple_FromPyObject (PyObject * pyobj)
368
 
{
369
 
  return ((C_BezTriple *) pyobj)->beztriple;
 
443
BezTriple *BezTriple_FromPyObject( PyObject * pyobj )
 
444
{
 
445
        return ( ( BPy_BezTriple * ) pyobj )->beztriple;
 
446
}
 
447
 
 
448
 
 
449
/*
 
450
  Create a new BezTriple
 
451
  input args is a sequence - either 3 or 9 floats
 
452
*/
 
453
 
 
454
PyObject *newBezTriple( PyObject *args)
 
455
{
 
456
        BPy_BezTriple *pybez = NULL;
 
457
        int length;
 
458
        float numbuf[9];
 
459
/*
 
460
  check input args:
 
461
    sequence of nine floats - x,y,z for h1, pt, h2
 
462
    sequence of 3 floats - x,y,z for pt with zero len handles in AUTO mode
 
463
*/
 
464
 
 
465
        /* do we have a sequence of the right length? */
 
466
 
 
467
        if( ! PySequence_Check( args )) {
 
468
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
469
                                                "expected better stuff"));
 
470
        }
 
471
        
 
472
        length = PySequence_Length( args );
 
473
        if( length != 9 && length != 3 )
 
474
                return  EXPP_ReturnPyObjError( PyExc_AttributeError,
 
475
                                               "wrong number of points");
 
476
        {
 
477
                int i;
 
478
                PyObject *pyo;
 
479
                for( i = 0; i < length; i++) {
 
480
                        pyo = PySequence_GetItem( args, i );
 
481
                        if( !pyo )
 
482
                                return EXPP_ReturnPyObjError
 
483
                                        ( PyExc_AttributeError,
 
484
                                          "wrong number of points");
 
485
                        if( !PyFloat_Check( pyo ))
 
486
                                return EXPP_ReturnPyObjError
 
487
                                        ( PyExc_AttributeError,
 
488
                                          "sequence item not number");
 
489
 
 
490
                        numbuf[i] = (float) PyFloat_AsDouble( pyo );
 
491
                        Py_DECREF( pyo );  /* from GetItem() */
 
492
                }
 
493
        }
 
494
                                
 
495
 
 
496
        /* create our bpy object */
 
497
        pybez = ( BPy_BezTriple* ) PyObject_New( BPy_BezTriple,
 
498
                                               &BezTriple_Type );
 
499
        if( ! pybez )
 
500
                return  EXPP_ReturnPyObjError( PyExc_MemoryError,
 
501
                                               "PyObject_New failed");
 
502
        pybez->beztriple = MEM_callocN( sizeof( BezTriple ), "new bpytriple");
 
503
        /* check malloc */
 
504
 
 
505
        pybez->own_memory = 1;  /* we own it. must free later */
 
506
 
 
507
        
 
508
        switch( length ) {
 
509
        case 9: {
 
510
                int i,j;
 
511
                int num = 0;
 
512
                for( i = 0; i < 3; i++ ){
 
513
                        for( j = 0; j < 3; j++){
 
514
                                pybez->beztriple->vec[i][j] = numbuf[num ++];
 
515
                        }
 
516
                }
 
517
        }
 
518
                break;
 
519
        case 3: {
 
520
                int i;
 
521
                int num = 0;
 
522
                /* set h1, pt, and h2 to the same values. */
 
523
                for( i = 0; i < 3; i++ ) {
 
524
                        pybez->beztriple->vec[0][i] = numbuf[num];
 
525
                        pybez->beztriple->vec[1][i] = numbuf[num];
 
526
                        pybez->beztriple->vec[2][i] = numbuf[num];
 
527
                        ++num;
 
528
                }
 
529
        }
 
530
                break;
 
531
        default:
 
532
                /* we should not be here! */
 
533
                break;
 
534
        }
 
535
 
 
536
 
 
537
        pybez->beztriple->h1 = HD_AUTO;
 
538
        pybez->beztriple->h2 = HD_AUTO;
 
539
 
 
540
        return ( PyObject* ) pybez;
370
541
}