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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Build.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: Build.c,v 1.9 2005/03/09 19:45:55 lukep Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
42
43
 
43
44
#include <stdio.h>
44
45
 
 
46
/* prototypes */
 
47
PyObject *Build_Init( void );
 
48
 
45
49
/*****************************************************************************/
46
 
/* Python BPy_Build methods table:                                             */
 
50
/* Python BPy_Build methods table:                                           */
47
51
/*****************************************************************************/
48
52
static PyMethodDef BPy_Build_methods[] = {
49
 
  {"getLen", (PyCFunction) Build_getLen,
50
 
   METH_NOARGS, "()-Return Build len"},
51
 
  {"setLen", (PyCFunction) Build_setLen, METH_VARARGS,
52
 
   "()- Sets Build len"},
53
 
  {"getSfra", (PyCFunction) Build_getSfra,
54
 
   METH_NOARGS, "()-Return Build sfra"},
55
 
  {"setSfra", (PyCFunction) Build_setSfra, METH_VARARGS,
56
 
   "()- Sets Build sfra"},
57
 
  {NULL, NULL, 0, NULL}
 
53
        {"getLen", ( PyCFunction ) Build_getLen,
 
54
         METH_NOARGS, "()-Return Build len"},
 
55
        {"setLen", ( PyCFunction ) Build_setLen, METH_VARARGS,
 
56
         "()- Sets Build len"},
 
57
        {"getSfra", ( PyCFunction ) Build_getSfra,
 
58
         METH_NOARGS, "()-Return Build sfra"},
 
59
        {"setSfra", ( PyCFunction ) Build_setSfra, METH_VARARGS,
 
60
         "()- Sets Build sfra"},
 
61
        {NULL, NULL, 0, NULL}
58
62
};
59
63
 
60
64
 
62
66
/* Python Build_Type structure definition:                                   */
63
67
/*****************************************************************************/
64
68
PyTypeObject Build_Type = {
65
 
  PyObject_HEAD_INIT (NULL) 0,  /* ob_size */
66
 
  "Build",                      /* tp_name */
67
 
  sizeof (BPy_Build),           /* tp_basicsize */
68
 
  0,                            /* tp_itemsize */
69
 
  /* methods */
70
 
  (destructor) BuildDeAlloc,    /* tp_dealloc */
71
 
  0,                            /* tp_print */
72
 
  (getattrfunc) BuildGetAttr,   /* tp_getattr */
73
 
  (setattrfunc) BuildSetAttr,   /* tp_setattr */
74
 
  0,                            /* tp_compare */
75
 
  (reprfunc) BuildRepr,         /* tp_repr */
76
 
  0,                            /* tp_as_number */
77
 
  0,                            /* tp_as_sequence */
78
 
  0,                            /* tp_as_mapping */
79
 
  0,                            /* tp_as_hash */
80
 
  0, 0, 0, 0, 0, 0,
81
 
  0,                            /* tp_doc */
82
 
  0, 0, 0, 0, 0, 0,
83
 
  BPy_Build_methods,            /* tp_methods */
84
 
  0,                            /* tp_members */
 
69
        PyObject_HEAD_INIT( NULL ) 
 
70
        0,      /* ob_size */
 
71
        "Build",                /* tp_name */
 
72
        sizeof( BPy_Build ),    /* tp_basicsize */
 
73
        0,                      /* tp_itemsize */
 
74
        /* methods */
 
75
        ( destructor ) BuildDeAlloc,    /* tp_dealloc */
 
76
        0,                      /* tp_print */
 
77
        ( getattrfunc ) BuildGetAttr,   /* tp_getattr */
 
78
        ( setattrfunc ) BuildSetAttr,   /* tp_setattr */
 
79
        0,                      /* tp_compare */
 
80
        ( reprfunc ) BuildRepr, /* tp_repr */
 
81
        0,                      /* tp_as_number */
 
82
        0,                      /* tp_as_sequence */
 
83
        0,                      /* tp_as_mapping */
 
84
        0,                      /* tp_as_hash */
 
85
        0, 0, 0, 0, 0, 0,
 
86
        0,                      /* tp_doc */
 
87
        0, 0, 0, 0, 0, 0,
 
88
        BPy_Build_methods,      /* tp_methods */
 
89
        0,                      /* tp_members */
85
90
};
86
91
 
87
92
 
107
112
/* Function:              M_Build_New                                        */
108
113
/* Python equivalent:     Blender.Effect.Build.New                           */
109
114
/*****************************************************************************/
110
 
PyObject *
111
 
M_Build_New (PyObject * self, PyObject * args)
 
115
PyObject *M_Build_New( PyObject * self, PyObject * args )
112
116
{
113
 
  int type = EFF_BUILD;
114
 
  BPy_Effect *pyeffect;
115
 
  Effect *bleffect = 0;
116
 
 
117
 
 
118
 
  bleffect = add_effect (type);
119
 
  if (bleffect == NULL)
120
 
    return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
121
 
                                   "couldn't create Effect Data in Blender"));
122
 
 
123
 
  pyeffect = (BPy_Effect *) PyObject_NEW (BPy_Effect, &Effect_Type);
124
 
 
125
 
 
126
 
  if (pyeffect == NULL)
127
 
    return (EXPP_ReturnPyObjError (PyExc_MemoryError,
128
 
                                   "couldn't create Effect Data object"));
129
 
 
130
 
  pyeffect->effect = bleffect;
131
 
 
132
 
  return (PyObject *) pyeffect;
133
 
  return 0;
 
117
        int type = EFF_BUILD;
 
118
        BPy_Effect *pyeffect;
 
119
        Effect *bleffect = 0;
 
120
 
 
121
 
 
122
        bleffect = add_effect( type );
 
123
        if( bleffect == NULL )
 
124
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
125
                                                "couldn't create Effect Data in Blender" ) );
 
126
 
 
127
        pyeffect = ( BPy_Effect * ) PyObject_NEW( BPy_Effect, &Effect_Type );
 
128
 
 
129
 
 
130
        if( pyeffect == NULL )
 
131
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
132
                                                "couldn't create Effect Data object" ) );
 
133
 
 
134
        pyeffect->effect = bleffect;
 
135
 
 
136
        return ( PyObject * ) pyeffect;
 
137
        return 0;
134
138
}
135
139
 
136
140
/*****************************************************************************/
137
141
/* Function:              M_Build_Get                                        */
138
142
/* Python equivalent:     Blender.Effect.Build.Get                           */
139
143
/*****************************************************************************/
140
 
PyObject *
141
 
M_Build_Get (PyObject * self, PyObject * args)
 
144
PyObject *M_Build_Get( PyObject * self, PyObject * args )
142
145
{
143
 
  /*arguments : string object name
144
 
     int : position of effect in the obj's effect list  */
145
 
  char *name = 0;
146
 
  Object *object_iter;
147
 
  Effect *eff;
148
 
  BPy_Build *wanted_eff;
149
 
  int num, i;
150
 
  if (!PyArg_ParseTuple (args, "si", &name, &num))
151
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
152
 
                                   "expected string int argument"));
153
 
 
154
 
  object_iter = G.main->object.first;
155
 
  if (!object_iter)
156
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
157
 
                                   "Scene contains no object"));
158
 
 
159
 
  while (object_iter)
160
 
    {
161
 
      if (strcmp (name, object_iter->id.name + 2))
162
 
        {
163
 
          object_iter = object_iter->id.next;
164
 
          continue;
165
 
        }
166
 
 
167
 
 
168
 
      if (object_iter->effect.first != NULL)
169
 
        {
170
 
          eff = object_iter->effect.first;
171
 
          for (i = 0; i < num; i++)
172
 
            {
173
 
              if (eff->type != EFF_BUILD)
174
 
                continue;
175
 
              eff = eff->next;
176
 
              if (!eff)
177
 
                return (EXPP_ReturnPyObjError
178
 
                        (PyExc_AttributeError, "object not created"));
179
 
            }
180
 
          wanted_eff = (BPy_Build *) PyObject_NEW (BPy_Build, &Build_Type);
181
 
          wanted_eff->build = eff;
182
 
          return (PyObject *) wanted_eff;
183
 
        }
184
 
      object_iter = object_iter->id.next;
185
 
    }
186
 
  Py_INCREF (Py_None);
187
 
  return Py_None;
 
146
        /*arguments : string object name
 
147
           int : position of effect in the obj's effect list  */
 
148
        char *name = 0;
 
149
        Object *object_iter;
 
150
        Effect *eff;
 
151
        BPy_Build *wanted_eff;
 
152
        int num, i;
 
153
        if( !PyArg_ParseTuple( args, "si", &name, &num ) )
 
154
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
155
                                                "expected string int argument" ) );
 
156
 
 
157
        object_iter = G.main->object.first;
 
158
        if( !object_iter )
 
159
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
160
                                                "Scene contains no object" ) );
 
161
 
 
162
        while( object_iter ) {
 
163
                if( strcmp( name, object_iter->id.name + 2 ) ) {
 
164
                        object_iter = object_iter->id.next;
 
165
                        continue;
 
166
                }
 
167
 
 
168
 
 
169
                if( object_iter->effect.first != NULL ) {
 
170
                        eff = object_iter->effect.first;
 
171
                        for( i = 0; i < num; i++ ) {
 
172
                                if( eff->type != EFF_BUILD )
 
173
                                        continue;
 
174
                                eff = eff->next;
 
175
                                if( !eff )
 
176
                                        return ( EXPP_ReturnPyObjError
 
177
                                                 ( PyExc_AttributeError,
 
178
                                                   "object not created" ) );
 
179
                        }
 
180
                        wanted_eff =
 
181
                                ( BPy_Build * ) PyObject_NEW( BPy_Build,
 
182
                                                              &Build_Type );
 
183
                        wanted_eff->build = eff;
 
184
                        return ( PyObject * ) wanted_eff;
 
185
                }
 
186
                object_iter = object_iter->id.next;
 
187
        }
 
188
        Py_INCREF( Py_None );
 
189
        return Py_None;
188
190
}
189
191
 
190
192
 
191
193
 
192
194
struct PyMethodDef M_Build_methods[] = {
193
 
  {"New", (PyCFunction) M_Build_New, METH_VARARGS, M_Build_New_doc},
194
 
  {"Get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
195
 
  {"get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
196
 
  {NULL, NULL, 0, NULL}
 
195
        {"New", ( PyCFunction ) M_Build_New, METH_VARARGS, M_Build_New_doc},
 
196
        {"Get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
 
197
        {"get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
 
198
        {NULL, NULL, 0, NULL}
197
199
};
198
200
 
199
201
/*****************************************************************************/
200
202
/* Function:              Build_Init                                         */
201
203
/*****************************************************************************/
202
204
 
203
 
PyObject *
204
 
Build_Init (void)
205
 
{
206
 
  PyObject *submodule;
207
 
 
208
 
  Build_Type.ob_type = &PyType_Type;
209
 
  submodule = Py_InitModule3 ("Blender.Build", M_Build_methods, M_Build_doc);
210
 
  return (submodule);
211
 
}
212
 
 
213
 
/*****************************************************************************/
214
 
/* Python BPy_Build methods:                                                  */
215
 
/*****************************************************************************/
216
 
 
217
 
PyObject *
218
 
Build_getLen (BPy_Build * self)
219
 
{
220
 
  BuildEff *ptr = (BuildEff *) self->build;
221
 
  return PyFloat_FromDouble (ptr->len);
222
 
}
223
 
 
224
 
 
225
 
PyObject *
226
 
Build_setLen (BPy_Build * self, PyObject * args)
227
 
{
228
 
  BuildEff *ptr = (BuildEff *) self->build;
229
 
  float val = 0;
230
 
  if (!PyArg_ParseTuple (args, "f", &val))
231
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
232
 
                                   "expected float argument"));
233
 
  ptr->len = val;
234
 
  Py_INCREF (Py_None);
235
 
  return Py_None;
236
 
}
237
 
 
238
 
 
239
 
PyObject *
240
 
Build_getSfra (BPy_Build * self)
241
 
{
242
 
  BuildEff *ptr = (BuildEff *) self->build;
243
 
  return PyFloat_FromDouble (ptr->sfra);
244
 
}
245
 
 
246
 
PyObject *
247
 
Build_setSfra (BPy_Build * self, PyObject * args)
248
 
{
249
 
  BuildEff *ptr = (BuildEff *) self->build;
250
 
  float val = 0;
251
 
  if (!PyArg_ParseTuple (args, "f", &val))
252
 
    return (EXPP_ReturnPyObjError
253
 
            (PyExc_AttributeError, "expected float argument"));
254
 
 
255
 
  ptr->sfra = val;
256
 
  Py_INCREF (Py_None);
257
 
  return Py_None;
 
205
PyObject *Build_Init( void )
 
206
{
 
207
        PyObject *submodule;
 
208
 
 
209
        Build_Type.ob_type = &PyType_Type;
 
210
        submodule =
 
211
                Py_InitModule3( "Blender.Build", M_Build_methods,
 
212
                                M_Build_doc );
 
213
        return ( submodule );
 
214
}
 
215
 
 
216
/*****************************************************************************/
 
217
/* Python BPy_Build methods:                                                */
 
218
/*****************************************************************************/
 
219
 
 
220
PyObject *Build_getLen( BPy_Build * self )
 
221
{
 
222
        BuildEff *ptr = ( BuildEff * ) self->build;
 
223
        return PyFloat_FromDouble( ptr->len );
 
224
}
 
225
 
 
226
 
 
227
PyObject *Build_setLen( BPy_Build * self, PyObject * args )
 
228
{
 
229
        BuildEff *ptr = ( BuildEff * ) self->build;
 
230
        float val = 0;
 
231
        if( !PyArg_ParseTuple( args, "f", &val ) )
 
232
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
233
                                                "expected float argument" ) );
 
234
        ptr->len = val;
 
235
        Py_INCREF( Py_None );
 
236
        return Py_None;
 
237
}
 
238
 
 
239
 
 
240
PyObject *Build_getSfra( BPy_Build * self )
 
241
{
 
242
        BuildEff *ptr = ( BuildEff * ) self->build;
 
243
        return PyFloat_FromDouble( ptr->sfra );
 
244
}
 
245
 
 
246
PyObject *Build_setSfra( BPy_Build * self, PyObject * args )
 
247
{
 
248
        BuildEff *ptr = ( BuildEff * ) self->build;
 
249
        float val = 0;
 
250
        if( !PyArg_ParseTuple( args, "f", &val ) )
 
251
                return ( EXPP_ReturnPyObjError
 
252
                         ( PyExc_AttributeError, "expected float argument" ) );
 
253
 
 
254
        ptr->sfra = val;
 
255
        Py_INCREF( Py_None );
 
256
        return Py_None;
258
257
}
259
258
 
260
259
/*****************************************************************************/
261
260
/* Function:    BuildDeAlloc                                                 */
262
 
/* Description: This is a callback function for the BPy_Build type. It is      */
 
261
/* Description: This is a callback function for the BPy_Build type. It is    */
263
262
/*              the destructor function.                                     */
264
263
/*****************************************************************************/
265
 
void
266
 
BuildDeAlloc (BPy_Build * self)
 
264
void BuildDeAlloc( BPy_Build * self )
267
265
{
268
 
  BuildEff *ptr = (BuildEff *) self;
269
 
  PyObject_DEL (ptr);
 
266
        BuildEff *ptr = ( BuildEff * ) self;
 
267
        PyObject_DEL( ptr );
270
268
}
271
269
 
272
270
/*****************************************************************************/
273
271
/* Function:    BuildGetAttr                                                 */
274
 
/* Description: This is a callback function for the BPy_Build type. It is      */
275
 
/*              the function that accesses BPy_Build "member variables" and    */
 
272
/* Description: This is a callback function for the BPy_Build type. It is    */
 
273
/*              the function that accesses BPy_Build "member variables" and  */
276
274
/*              methods.                                                     */
277
275
/*****************************************************************************/
278
276
 
279
 
PyObject *
280
 
BuildGetAttr (BPy_Build * self, char *name)
 
277
PyObject *BuildGetAttr( BPy_Build * self, char *name )
281
278
{
282
 
  if (!strcmp (name, "sfra"))
283
 
    return Build_getSfra (self);
284
 
  if (!strcmp (name, "len"))
285
 
    return Build_getLen (self);
286
 
  return Py_FindMethod (BPy_Build_methods, (PyObject *) self, name);
 
279
        if( !strcmp( name, "sfra" ) )
 
280
                return Build_getSfra( self );
 
281
        if( !strcmp( name, "len" ) )
 
282
                return Build_getLen( self );
 
283
        return Py_FindMethod( BPy_Build_methods, ( PyObject * ) self, name );
287
284
}
288
285
 
289
286
/*****************************************************************************/
290
 
/* Function:    BuildSetAttr                                                  */
291
 
/* Description: This is a callback function for the BPy_Build type. It is the   */
292
 
/*              function that sets Build Data attributes (member variables).  */
 
287
/* Function:    BuildSetAttr                                                 */
 
288
/* Description: This is a callback function for the BPy_Build type. It   */
 
289
/*              sets Build Data attributes (member variables).  */
293
290
/*****************************************************************************/
294
 
int
295
 
BuildSetAttr (BPy_Build * self, char *name, PyObject * value)
 
291
int BuildSetAttr( BPy_Build * self, char *name, PyObject * value )
296
292
{
297
 
  PyObject *valtuple;
298
 
  PyObject *error = NULL;
299
 
  valtuple = Py_BuildValue ("(N)", value);
300
 
 
301
 
  if (!valtuple)
302
 
    return EXPP_ReturnIntError (PyExc_MemoryError,
303
 
                                "CameraSetAttr: couldn't create PyTuple");
304
 
 
305
 
  if (!strcmp (name, "sfra"))
306
 
    error = Build_setSfra (self, valtuple);
307
 
  else if (!strcmp (name, "len"))
308
 
    error = Build_setLen (self, valtuple);
309
 
 
310
 
  else
311
 
    {
312
 
      Py_DECREF (valtuple);
313
 
      return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
314
 
    }
315
 
 
316
 
  /*  Py_DECREF(valtuple); */
317
 
 
318
 
  if (error != Py_None)
319
 
    return -1;
320
 
 
321
 
  Py_DECREF (Py_None);
322
 
  return 0;
 
293
        PyObject *valtuple;
 
294
        PyObject *error = NULL;
 
295
        valtuple = Py_BuildValue( "(N)", value );
 
296
 
 
297
        if( !valtuple )
 
298
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
299
                                            "CameraSetAttr: couldn't create PyTuple" );
 
300
 
 
301
        if( !strcmp( name, "sfra" ) )
 
302
                error = Build_setSfra( self, valtuple );
 
303
        else if( !strcmp( name, "len" ) )
 
304
                error = Build_setLen( self, valtuple );
 
305
 
 
306
        else {
 
307
                Py_DECREF( valtuple );
 
308
                return ( EXPP_ReturnIntError
 
309
                         ( PyExc_KeyError, "attribute not found" ) );
 
310
        }
 
311
 
 
312
        /*  Py_DECREF(valtuple); */
 
313
 
 
314
        if( error != Py_None )
 
315
                return -1;
 
316
 
 
317
        Py_DECREF( Py_None );
 
318
        return 0;
323
319
}
324
320
 
325
321
/*****************************************************************************/
326
322
/* Function:    BuildPrint                                                   */
327
 
/* Description: This is a callback function for the BPy_Build type. It         */
 
323
/* Description: This is a callback function for the BPy_Build type. It       */
328
324
/*              builds a meaninful string to 'print' build objects.          */
329
325
/*****************************************************************************/
330
326
/*
335
331
*/
336
332
/*****************************************************************************/
337
333
/* Function:    BuildRepr                                                    */
338
 
/* Description: This is a callback function for the BPy_Build type. It         */
 
334
/* Description: This is a callback function for the BPy_Build type. It       */
339
335
/*              builds a meaninful string to represent build objects.        */
340
336
/*****************************************************************************/
341
 
PyObject *
342
 
BuildRepr (BPy_Build * self)
343
 
{
344
 
  return PyString_FromString ("Build effect");
345
 
}
346
 
 
347
 
PyObject *
348
 
BuildCreatePyObject (struct Effect * build)
349
 
{
350
 
  BPy_Build *blen_object;
351
 
 
352
 
 
353
 
  blen_object = (BPy_Build *) PyObject_NEW (BPy_Build, &Build_Type);
354
 
 
355
 
  if (blen_object == NULL)
356
 
    {
357
 
      return (NULL);
358
 
    }
359
 
  blen_object->build = build;
360
 
  return ((PyObject *) blen_object);
361
 
 
362
 
}
363
 
 
364
 
int
365
 
BuildCheckPyObject (PyObject * py_obj)
366
 
{
367
 
  return (py_obj->ob_type == &Build_Type);
368
 
}
369
 
 
370
 
 
371
 
struct Build *
372
 
BuildFromPyObject (PyObject * py_obj)
373
 
{
374
 
  BPy_Build *blen_obj;
375
 
 
376
 
  blen_obj = (BPy_Build *) py_obj;
377
 
  return ((struct Build *) blen_obj->build);
 
337
PyObject *BuildRepr( BPy_Build * self )
 
338
{
 
339
        return PyString_FromString( "Build effect" );
 
340
}
 
341
 
 
342
PyObject *BuildCreatePyObject( struct Effect * build )
 
343
{
 
344
        BPy_Build *blen_object;
 
345
 
 
346
 
 
347
        blen_object = ( BPy_Build * ) PyObject_NEW( BPy_Build, &Build_Type );
 
348
 
 
349
        if( blen_object == NULL ) {
 
350
                return ( NULL );
 
351
        }
 
352
        blen_object->build = build;
 
353
        return ( ( PyObject * ) blen_object );
 
354
 
 
355
}
 
356
 
 
357
int BuildCheckPyObject( PyObject * py_obj )
 
358
{
 
359
        return ( py_obj->ob_type == &Build_Type );
 
360
}
 
361
 
 
362
 
 
363
struct Build *BuildFromPyObject( PyObject * py_obj )
 
364
{
 
365
        BPy_Build *blen_obj;
 
366
 
 
367
        blen_obj = ( BPy_Build * ) py_obj;
 
368
        return ( ( struct Build * ) blen_obj->build );
378
369
 
379
370
}