84
92
/* Python method structure definition for Blender.Camera module: */
85
93
/*****************************************************************************/
86
94
struct PyMethodDef M_Camera_methods[] = {
87
{"New", (PyCFunction) M_Camera_New, METH_VARARGS | METH_KEYWORDS,
89
{"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
90
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
95
{"New", ( PyCFunction ) M_Camera_New, METH_VARARGS | METH_KEYWORDS,
97
{"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
98
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
94
102
/*****************************************************************************/
95
103
/* Python BPy_Camera methods declarations: */
96
104
/*****************************************************************************/
97
static PyObject *Camera_getIpo (BPy_Camera * self);
98
static PyObject *Camera_getName (BPy_Camera * self);
99
static PyObject *Camera_getType (BPy_Camera * self);
100
static PyObject *Camera_getMode (BPy_Camera * self);
101
static PyObject *Camera_getLens (BPy_Camera * self);
102
static PyObject *Camera_getClipStart (BPy_Camera * self);
103
static PyObject *Camera_getClipEnd (BPy_Camera * self);
104
static PyObject *Camera_getDrawSize (BPy_Camera * self);
105
static PyObject *Camera_setIpo (BPy_Camera * self, PyObject * args);
106
static PyObject *Camera_clearIpo (BPy_Camera * self);
107
static PyObject *Camera_setName (BPy_Camera * self, PyObject * args);
108
static PyObject *Camera_setType (BPy_Camera * self, PyObject * args);
109
static PyObject *Camera_setIntType (BPy_Camera * self, PyObject * args);
110
static PyObject *Camera_setMode (BPy_Camera * self, PyObject * args);
111
static PyObject *Camera_setIntMode (BPy_Camera * self, PyObject * args);
112
static PyObject *Camera_setLens (BPy_Camera * self, PyObject * args);
113
static PyObject *Camera_setClipStart (BPy_Camera * self, PyObject * args);
114
static PyObject *Camera_setClipEnd (BPy_Camera * self, PyObject * args);
115
static PyObject *Camera_setDrawSize (BPy_Camera * self, PyObject * args);
105
static PyObject *Camera_getIpo( BPy_Camera * self );
106
static PyObject *Camera_getName( BPy_Camera * self );
107
static PyObject *Camera_getType( BPy_Camera * self );
108
static PyObject *Camera_getMode( BPy_Camera * self );
109
static PyObject *Camera_getLens( BPy_Camera * self );
110
static PyObject *Camera_getClipStart( BPy_Camera * self );
111
static PyObject *Camera_getClipEnd( BPy_Camera * self );
112
static PyObject *Camera_getDrawSize( BPy_Camera * self );
113
static PyObject *Camera_getScale( BPy_Camera * self );
114
static PyObject *Camera_setIpo( BPy_Camera * self, PyObject * args );
115
static PyObject *Camera_clearIpo( BPy_Camera * self );
116
static PyObject *Camera_setName( BPy_Camera * self, PyObject * args );
117
static PyObject *Camera_setType( BPy_Camera * self, PyObject * args );
118
static PyObject *Camera_setIntType( BPy_Camera * self, PyObject * args );
119
static PyObject *Camera_setMode( BPy_Camera * self, PyObject * args );
120
static PyObject *Camera_setIntMode( BPy_Camera * self, PyObject * args );
121
static PyObject *Camera_setLens( BPy_Camera * self, PyObject * args );
122
static PyObject *Camera_setClipStart( BPy_Camera * self, PyObject * args );
123
static PyObject *Camera_setClipEnd( BPy_Camera * self, PyObject * args );
124
static PyObject *Camera_setDrawSize( BPy_Camera * self, PyObject * args );
125
static PyObject *Camera_setScale( BPy_Camera * self, PyObject * args );
126
static PyObject *Camera_getScriptLinks( BPy_Camera * self, PyObject * args );
127
static PyObject *Camera_addScriptLink( BPy_Camera * self, PyObject * args );
128
static PyObject *Camera_clearScriptLinks( BPy_Camera * self, PyObject * args );
129
static PyObject *Camera_insertIpoKey( BPy_Camera * self, PyObject * args );
131
Camera *GetCameraByName( char *name );
117
134
/*****************************************************************************/
118
135
/* Python BPy_Camera methods table: */
119
136
/*****************************************************************************/
120
137
static PyMethodDef BPy_Camera_methods[] = {
121
/* name, method, flags, doc */
122
{"getIpo", (PyCFunction) Camera_getIpo, METH_NOARGS,
123
"() - Return Camera Data Ipo"},
124
{"getName", (PyCFunction) Camera_getName, METH_NOARGS,
125
"() - Return Camera Data name"},
126
{"getType", (PyCFunction) Camera_getType, METH_NOARGS,
127
"() - Return Camera type - 'persp':0, 'ortho':1"},
128
{"getMode", (PyCFunction) Camera_getMode, METH_NOARGS,
129
"() - Return Camera mode flags (or'ed value) -\n"
130
" 'showLimits':1, 'showMist':2"},
131
{"getLens", (PyCFunction) Camera_getLens, METH_NOARGS,
132
"() - Return Camera lens value"},
133
{"getClipStart", (PyCFunction) Camera_getClipStart, METH_NOARGS,
134
"() - Return Camera clip start value"},
135
{"getClipEnd", (PyCFunction) Camera_getClipEnd, METH_NOARGS,
136
"() - Return Camera clip end value"},
137
{"getDrawSize", (PyCFunction) Camera_getDrawSize, METH_NOARGS,
138
"() - Return Camera draw size value"},
139
{"setIpo", (PyCFunction) Camera_setIpo, METH_VARARGS,
140
"(Blender Ipo) - Set Camera Ipo"},
141
{"clearIpo", (PyCFunction) Camera_clearIpo, METH_NOARGS,
142
"() - Unlink Ipo from this Camera."},
143
{"setName", (PyCFunction) Camera_setName, METH_VARARGS,
144
"(s) - Set Camera Data name"},
145
{"setType", (PyCFunction) Camera_setType, METH_VARARGS,
146
"(s) - Set Camera type, which can be 'persp' or 'ortho'"},
147
{"setMode", (PyCFunction) Camera_setMode, METH_VARARGS,
148
"(<s<,s>>) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
149
{"setLens", (PyCFunction) Camera_setLens, METH_VARARGS,
150
"(f) - Set Camera lens value"},
151
{"setClipStart", (PyCFunction) Camera_setClipStart, METH_VARARGS,
152
"(f) - Set Camera clip start value"},
153
{"setClipEnd", (PyCFunction) Camera_setClipEnd, METH_VARARGS,
154
"(f) - Set Camera clip end value"},
155
{"setDrawSize", (PyCFunction) Camera_setDrawSize, METH_VARARGS,
156
"(f) - Set Camera draw size value"},
157
{NULL, NULL, 0, NULL}
138
/* name, method, flags, doc */
139
{"getIpo", ( PyCFunction ) Camera_getIpo, METH_NOARGS,
140
"() - Return Camera Data Ipo"},
141
{"getName", ( PyCFunction ) Camera_getName, METH_NOARGS,
142
"() - Return Camera Data name"},
143
{"getType", ( PyCFunction ) Camera_getType, METH_NOARGS,
144
"() - Return Camera type - 'persp':0, 'ortho':1"},
145
{"getMode", ( PyCFunction ) Camera_getMode, METH_NOARGS,
146
"() - Return Camera mode flags (or'ed value) -\n"
147
" 'showLimits':1, 'showMist':2"},
148
{"getLens", ( PyCFunction ) Camera_getLens, METH_NOARGS,
149
"() - Return *perspective* Camera lens value"},
150
{"getScale", ( PyCFunction ) Camera_getScale, METH_NOARGS,
151
"() - Return *ortho* Camera scale value"},
152
{"getClipStart", ( PyCFunction ) Camera_getClipStart, METH_NOARGS,
153
"() - Return Camera clip start value"},
154
{"getClipEnd", ( PyCFunction ) Camera_getClipEnd, METH_NOARGS,
155
"() - Return Camera clip end value"},
156
{"getDrawSize", ( PyCFunction ) Camera_getDrawSize, METH_NOARGS,
157
"() - Return Camera draw size value"},
158
{"setIpo", ( PyCFunction ) Camera_setIpo, METH_VARARGS,
159
"(Blender Ipo) - Set Camera Ipo"},
160
{"clearIpo", ( PyCFunction ) Camera_clearIpo, METH_NOARGS,
161
"() - Unlink Ipo from this Camera."},
162
{"insertIpoKey", ( PyCFunction ) Camera_insertIpoKey, METH_VARARGS,
163
"( Camera IPO type ) - Inserts a key into IPO"},
164
{"setName", ( PyCFunction ) Camera_setName, METH_VARARGS,
165
"(s) - Set Camera Data name"},
166
{"setType", ( PyCFunction ) Camera_setType, METH_VARARGS,
167
"(s) - Set Camera type, which can be 'persp' or 'ortho'"},
168
{"setMode", ( PyCFunction ) Camera_setMode, METH_VARARGS,
169
"(<s<,s>>) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
170
{"setLens", ( PyCFunction ) Camera_setLens, METH_VARARGS,
171
"(f) - Set *perpective* Camera lens value"},
172
{"setScale", ( PyCFunction ) Camera_setScale, METH_VARARGS,
173
"(f) - Set *ortho* Camera scale value"},
174
{"setClipStart", ( PyCFunction ) Camera_setClipStart, METH_VARARGS,
175
"(f) - Set Camera clip start value"},
176
{"setClipEnd", ( PyCFunction ) Camera_setClipEnd, METH_VARARGS,
177
"(f) - Set Camera clip end value"},
178
{"setDrawSize", ( PyCFunction ) Camera_setDrawSize, METH_VARARGS,
179
"(f) - Set Camera draw size value"},
180
{"getScriptLinks", ( PyCFunction ) Camera_getScriptLinks, METH_VARARGS,
181
"(eventname) - Get a list of this camera's scriptlinks (Text names) "
182
"of the given type\n"
183
"(eventname) - string: FrameChanged, Redraw or Render."},
184
{"addScriptLink", ( PyCFunction ) Camera_addScriptLink, METH_VARARGS,
185
"(text, evt) - Add a new camera scriptlink.\n"
186
"(text) - string: an existing Blender Text name;\n"
187
"(evt) string: FrameChanged, Redraw or Render."},
188
{"clearScriptLinks", ( PyCFunction ) Camera_clearScriptLinks,
190
"() - Delete all scriptlinks from this camera.\n"
191
"([s1<,s2,s3...>]) - Delete specified scriptlinks from this camera."},
192
{NULL, NULL, 0, NULL}
160
195
/*****************************************************************************/
161
196
/* Python Camera_Type callback function prototypes: */
162
197
/*****************************************************************************/
163
static void Camera_dealloc (BPy_Camera * self);
164
static int Camera_setAttr (BPy_Camera * self, char *name, PyObject * v);
165
static int Camera_compare (BPy_Camera * a, BPy_Camera * b);
166
static PyObject *Camera_getAttr (BPy_Camera * self, char *name);
167
static PyObject *Camera_repr (BPy_Camera * self);
198
static void Camera_dealloc( BPy_Camera * self );
199
static int Camera_setAttr( BPy_Camera * self, char *name, PyObject * v );
200
static int Camera_compare( BPy_Camera * a, BPy_Camera * b );
201
static PyObject *Camera_getAttr( BPy_Camera * self, char *name );
202
static PyObject *Camera_repr( BPy_Camera * self );
170
205
/*****************************************************************************/
171
/* Python Camera_Type structure definition: */
206
/* Python Camera_Type structure definition: */
172
207
/*****************************************************************************/
173
208
PyTypeObject Camera_Type = {
174
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
175
"Blender Camera", /* tp_name */
176
sizeof (BPy_Camera), /* tp_basicsize */
179
(destructor) Camera_dealloc, /* tp_dealloc */
181
(getattrfunc) Camera_getAttr, /* tp_getattr */
182
(setattrfunc) Camera_setAttr, /* tp_setattr */
183
(cmpfunc) Camera_compare, /* tp_compare */
184
(reprfunc) Camera_repr, /* tp_repr */
185
0, /* tp_as_number */
186
0, /* tp_as_sequence */
187
0, /* tp_as_mapping */
192
BPy_Camera_methods, /* tp_methods */
209
PyObject_HEAD_INIT( NULL ) /* required macro */
211
"Blender Camera", /* tp_name */
212
sizeof( BPy_Camera ), /* tp_basicsize */
215
( destructor ) Camera_dealloc, /* tp_dealloc */
217
( getattrfunc ) Camera_getAttr, /* tp_getattr */
218
( setattrfunc ) Camera_setAttr, /* tp_setattr */
219
( cmpfunc ) Camera_compare, /* tp_compare */
220
( reprfunc ) Camera_repr, /* tp_repr */
221
0, /* tp_as_number */
222
0, /* tp_as_sequence */
223
0, /* tp_as_mapping */
228
BPy_Camera_methods, /* tp_methods */
230
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
197
M_Camera_New (PyObject * self, PyObject * args, PyObject * kwords)
199
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
200
char *name_str = "CamData";
201
static char *kwlist[] = { "type_str", "name_str", NULL };
202
PyObject *pycam; /* for Camera Data object wrapper in Python */
203
Camera *blcam; /* for actual Camera Data we create in Blender */
206
/* Parse the arguments passed in by the Python interpreter */
207
if (!PyArg_ParseTupleAndKeywords (args, kwords, "|ss", kwlist,
208
&type_str, &name_str))
209
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
210
return EXPP_ReturnPyObjError (PyExc_AttributeError,
211
"expected zero, one or two strings as arguments");
213
blcam = add_camera (); /* first create the Camera Data in Blender */
215
if (blcam) /* now create the wrapper obj in Python */
216
pycam = Camera_CreatePyObject (blcam);
218
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
219
"couldn't create Camera Data in Blender");
221
/* let's return user count to zero, because ... */
222
blcam->id.us = 0; /* ... add_camera() incref'ed it */
223
/* XXX XXX Do this in other modules, too */
226
return EXPP_ReturnPyObjError (PyExc_MemoryError,
227
"couldn't create Camera PyObject");
229
if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */
230
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP */ ;
231
/* we comment this line */
232
else if (strcmp (type_str, "ortho") == 0)
233
blcam->type = (short) EXPP_CAM_TYPE_ORTHO;
235
return EXPP_ReturnPyObjError (PyExc_AttributeError,
236
"unknown camera type");
238
if (strcmp (name_str, "CamData") == 0)
241
{ /* user gave us a name for the camera, use it */
242
PyOS_snprintf (buf, sizeof (buf), "%s", name_str);
243
rename_id (&blcam->id, buf); /* proper way in Blender */
250
M_Camera_Get (PyObject * self, PyObject * args)
255
if (!PyArg_ParseTuple (args, "|s", &name))
256
return EXPP_ReturnPyObjError (PyExc_TypeError,
257
"expected string argument (or nothing)");
259
cam_iter = G.main->camera.first;
262
{ /* (name) - Search camera by name */
264
PyObject *wanted_cam = NULL;
266
while (cam_iter && !wanted_cam)
269
if (strcmp (name, cam_iter->id.name + 2) == 0)
271
wanted_cam = Camera_CreatePyObject (cam_iter);
275
cam_iter = cam_iter->id.next;
279
{ /* Requested camera doesn't exist */
281
PyOS_snprintf (error_msg, sizeof (error_msg),
282
"Camera \"%s\" not found", name);
283
return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
290
{ /* () - return a list of wrappers for all cameras in the scene */
292
PyObject *cam_pylist, *pyobj;
294
cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
297
return PythonReturnErrorObject (PyExc_MemoryError,
298
"couldn't create PyList");
302
pyobj = Camera_CreatePyObject (cam_iter);
305
return PythonReturnErrorObject (PyExc_MemoryError,
306
"couldn't create Camera PyObject");
308
PyList_SET_ITEM (cam_pylist, index, pyobj);
310
cam_iter = cam_iter->id.next;
323
Camera_Type.ob_type = &PyType_Type;
325
submodule = Py_InitModule3 ("Blender.Camera",
326
M_Camera_methods, M_Camera_doc);
233
static PyObject *M_Camera_New( PyObject * self, PyObject * args,
236
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
237
char *name_str = "CamData";
238
static char *kwlist[] = { "type_str", "name_str", NULL };
239
PyObject *pycam; /* for Camera Data object wrapper in Python */
240
Camera *blcam; /* for actual Camera Data we create in Blender */
243
/* Parse the arguments passed in by the Python interpreter */
244
if( !PyArg_ParseTupleAndKeywords( args, kwords, "|ss", kwlist,
245
&type_str, &name_str ) )
246
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
247
return EXPP_ReturnPyObjError( PyExc_AttributeError,
248
"expected zero, one or two strings as arguments" );
250
blcam = add_camera( ); /* first create the Camera Data in Blender */
252
if( blcam ) /* now create the wrapper obj in Python */
253
pycam = Camera_CreatePyObject( blcam );
255
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
256
"couldn't create Camera Data in Blender" );
258
/* let's return user count to zero, because ... */
259
blcam->id.us = 0; /* ... add_camera() incref'ed it */
260
/* XXX XXX Do this in other modules, too */
263
return EXPP_ReturnPyObjError( PyExc_MemoryError,
264
"couldn't create Camera PyObject" );
266
if( strcmp( type_str, "persp" ) == 0 )
267
/* default, no need to set, so */
268
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP */
270
/* we comment this line */
271
else if( strcmp( type_str, "ortho" ) == 0 )
272
blcam->type = ( short ) EXPP_CAM_TYPE_ORTHO;
274
return EXPP_ReturnPyObjError( PyExc_AttributeError,
275
"unknown camera type" );
277
if( strcmp( name_str, "CamData" ) == 0 )
279
else { /* user gave us a name for the camera, use it */
280
PyOS_snprintf( buf, sizeof( buf ), "%s", name_str );
281
rename_id( &blcam->id, buf ); /* proper way in Blender */
287
static PyObject *M_Camera_Get( PyObject * self, PyObject * args )
292
if( !PyArg_ParseTuple( args, "|s", &name ) )
293
return EXPP_ReturnPyObjError( PyExc_TypeError,
294
"expected string argument (or nothing)" );
296
cam_iter = G.main->camera.first;
298
if( name ) { /* (name) - Search camera by name */
300
PyObject *wanted_cam = NULL;
302
while( cam_iter && !wanted_cam ) {
304
if( strcmp( name, cam_iter->id.name + 2 ) == 0 ) {
305
wanted_cam = Camera_CreatePyObject( cam_iter );
309
cam_iter = cam_iter->id.next;
312
if( !wanted_cam ) { /* Requested camera doesn't exist */
314
PyOS_snprintf( error_msg, sizeof( error_msg ),
315
"Camera \"%s\" not found", name );
316
return EXPP_ReturnPyObjError( PyExc_NameError,
323
else { /* () - return a list of wrappers for all cameras in the scene */
325
PyObject *cam_pylist, *pyobj;
328
PyList_New( BLI_countlist( &( G.main->camera ) ) );
331
return EXPP_ReturnPyObjError( PyExc_MemoryError,
332
"couldn't create PyList" );
335
pyobj = Camera_CreatePyObject( cam_iter );
338
return EXPP_ReturnPyObjError
340
"couldn't create Camera PyObject" );
342
PyList_SET_ITEM( cam_pylist, index, pyobj );
344
cam_iter = cam_iter->id.next;
352
PyObject *Camera_Init( void )
356
Camera_Type.ob_type = &PyType_Type;
358
submodule = Py_InitModule3( "Blender.Camera",
359
M_Camera_methods, M_Camera_doc );
361
PyModule_AddIntConstant( submodule, "LENS", IPOKEY_LENS );
362
PyModule_AddIntConstant( submodule, "CLIPPING", IPOKEY_CLIPPING );
331
367
/* Three Python Camera_Type helper functions needed by the Object module: */
334
Camera_CreatePyObject (Camera * cam)
338
pycam = (BPy_Camera *) PyObject_NEW (BPy_Camera, &Camera_Type);
341
return EXPP_ReturnPyObjError (PyExc_MemoryError,
342
"couldn't create BPy_Camera PyObject");
346
return (PyObject *) pycam;
350
Camera_CheckPyObject (PyObject * pyobj)
352
return (pyobj->ob_type == &Camera_Type);
356
Camera_FromPyObject (PyObject * pyobj)
358
return ((BPy_Camera *) pyobj)->camera;
361
/*****************************************************************************/
362
/* Description: Returns the object with the name specified by the argument */
363
/* name. Note that the calling function has to remove the first */
364
/* two characters of the object name. These two characters */
365
/* specify the type of the object (OB, ME, WO, ...) */
366
/* The function will return NULL when no object with the given */
368
/*****************************************************************************/
370
GetCameraByName (char *name)
374
cam_iter = G.main->camera.first;
377
if (StringEqual (name, GetIdName (&(cam_iter->id))))
381
cam_iter = cam_iter->id.next;
384
/* There is no camera with the given name */
388
/*****************************************************************************/
389
/* Python BPy_Camera methods: */
390
/*****************************************************************************/
393
Camera_getIpo (BPy_Camera * self)
395
struct Ipo *ipo = self->camera->ipo;
403
return Ipo_CreatePyObject (ipo);
412
Camera_getName (BPy_Camera * self)
415
PyObject *attr = PyString_FromString (self->camera->id.name + 2);
420
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
421
"couldn't get Camera.name attribute");
425
Camera_getType (BPy_Camera * self)
427
PyObject *attr = PyInt_FromLong (self->camera->type);
432
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
433
"couldn't get Camera.type attribute");
437
Camera_getMode (BPy_Camera * self)
439
PyObject *attr = PyInt_FromLong (self->camera->flag);
444
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
445
"couldn't get Camera.Mode attribute");
449
Camera_getLens (BPy_Camera * self)
451
PyObject *attr = PyFloat_FromDouble (self->camera->lens);
456
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
457
"couldn't get Camera.lens attribute");
461
Camera_getClipStart (BPy_Camera * self)
463
PyObject *attr = PyFloat_FromDouble (self->camera->clipsta);
468
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
469
"couldn't get Camera.clipStart attribute");
473
Camera_getClipEnd (BPy_Camera * self)
475
PyObject *attr = PyFloat_FromDouble (self->camera->clipend);
480
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
481
"couldn't get Camera.clipEnd attribute");
485
Camera_getDrawSize (BPy_Camera * self)
487
PyObject *attr = PyFloat_FromDouble (self->camera->drawsize);
492
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
493
"couldn't get Camera.drawSize attribute");
499
Camera_setIpo (BPy_Camera * self, PyObject * args)
505
if (!PyArg_ParseTuple (args, "O!", &Ipo_Type, &pyipo))
506
return EXPP_ReturnPyObjError (PyExc_TypeError,
507
"expected Ipo as argument");
509
ipo = Ipo_FromPyObject (pyipo);
512
return EXPP_ReturnPyObjError (PyExc_RuntimeError, "null ipo!");
514
if (ipo->blocktype != ID_CA)
515
return EXPP_ReturnPyObjError (PyExc_TypeError,
516
"this ipo is not a camera data ipo");
518
oldipo = self->camera->ipo;
521
ID *id = &oldipo->id;
526
((ID *) & ipo->id)->us++;
528
self->camera->ipo = ipo;
535
Camera_clearIpo (BPy_Camera * self)
537
Camera *cam = self->camera;
538
Ipo *ipo = (Ipo *) cam->ipo;
551
Py_INCREF (Py_False); /* no ipo found */
556
Camera_setName (BPy_Camera * self, PyObject * args)
561
if (!PyArg_ParseTuple (args, "s", &name))
562
return EXPP_ReturnPyObjError (PyExc_TypeError,
563
"expected string argument");
565
PyOS_snprintf (buf, sizeof (buf), "%s", name);
567
rename_id (&self->camera->id, buf);
574
Camera_setType (BPy_Camera * self, PyObject * args)
578
if (!PyArg_ParseTuple (args, "s", &type))
579
return EXPP_ReturnPyObjError (PyExc_TypeError,
580
"expected string argument");
582
if (strcmp (type, "persp") == 0)
583
self->camera->type = (short) EXPP_CAM_TYPE_PERSP;
584
else if (strcmp (type, "ortho") == 0)
585
self->camera->type = (short) EXPP_CAM_TYPE_ORTHO;
587
return EXPP_ReturnPyObjError (PyExc_AttributeError,
588
"unknown camera type");
369
PyObject *Camera_CreatePyObject( Camera * cam )
373
pycam = ( BPy_Camera * ) PyObject_NEW( BPy_Camera, &Camera_Type );
376
return EXPP_ReturnPyObjError( PyExc_MemoryError,
377
"couldn't create BPy_Camera PyObject" );
381
return ( PyObject * ) pycam;
384
int Camera_CheckPyObject( PyObject * pyobj )
386
return ( pyobj->ob_type == &Camera_Type );
389
Camera *Camera_FromPyObject( PyObject * pyobj )
391
return ( ( BPy_Camera * ) pyobj )->camera;
394
/*****************************************************************************/
395
/* Description: Returns the object with the name specified by the argument */
396
/* name. Note that the calling function has to remove the first */
397
/* two characters of the object name. These two characters */
398
/* specify the type of the object (OB, ME, WO, ...) */
399
/* The function will return NULL when no object with the given */
401
/*****************************************************************************/
402
Camera *GetCameraByName( char *name )
406
cam_iter = G.main->camera.first;
408
if( StringEqual( name, GetIdName( &( cam_iter->id ) ) ) ) {
411
cam_iter = cam_iter->id.next;
414
/* There is no camera with the given name */
418
/*****************************************************************************/
419
/* Python BPy_Camera methods: */
420
/*****************************************************************************/
422
static PyObject *Camera_getIpo( BPy_Camera * self )
424
struct Ipo *ipo = self->camera->ipo;
427
Py_INCREF( Py_None );
431
return Ipo_CreatePyObject( ipo );
439
static PyObject *Camera_getName( BPy_Camera * self )
442
PyObject *attr = PyString_FromString( self->camera->id.name + 2 );
447
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
448
"couldn't get Camera.name attribute" );
451
static PyObject *Camera_getType( BPy_Camera * self )
453
PyObject *attr = PyInt_FromLong( self->camera->type );
458
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
459
"couldn't get Camera.type attribute" );
462
static PyObject *Camera_getMode( BPy_Camera * self )
464
PyObject *attr = PyInt_FromLong( self->camera->flag );
469
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
470
"couldn't get Camera.Mode attribute" );
473
static PyObject *Camera_getLens( BPy_Camera * self )
475
PyObject *attr = PyFloat_FromDouble( self->camera->lens );
480
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
481
"couldn't get Camera.lens attribute" );
484
static PyObject *Camera_getScale( BPy_Camera * self )
486
PyObject *attr = PyFloat_FromDouble( self->camera->ortho_scale );
491
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
492
"couldn't get Camera.scale attribute" );
495
static PyObject *Camera_getClipStart( BPy_Camera * self )
497
PyObject *attr = PyFloat_FromDouble( self->camera->clipsta );
502
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
503
"couldn't get Camera.clipStart attribute" );
506
static PyObject *Camera_getClipEnd( BPy_Camera * self )
508
PyObject *attr = PyFloat_FromDouble( self->camera->clipend );
513
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
514
"couldn't get Camera.clipEnd attribute" );
517
static PyObject *Camera_getDrawSize( BPy_Camera * self )
519
PyObject *attr = PyFloat_FromDouble( self->camera->drawsize );
524
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
525
"couldn't get Camera.drawSize attribute" );
530
static PyObject *Camera_setIpo( BPy_Camera * self, PyObject * args )
536
if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) )
537
return EXPP_ReturnPyObjError( PyExc_TypeError,
538
"expected Ipo as argument" );
540
ipo = Ipo_FromPyObject( pyipo );
543
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
546
if( ipo->blocktype != ID_CA )
547
return EXPP_ReturnPyObjError( PyExc_TypeError,
548
"this ipo is not a camera data ipo" );
550
oldipo = self->camera->ipo;
552
ID *id = &oldipo->id;
557
( ( ID * ) & ipo->id )->us++;
559
self->camera->ipo = ipo;
561
Py_INCREF( Py_None );
565
static PyObject *Camera_clearIpo( BPy_Camera * self )
567
Camera *cam = self->camera;
568
Ipo *ipo = ( Ipo * ) cam->ipo;
576
return EXPP_incr_ret_True();
579
return EXPP_incr_ret_False(); /* no ipo found */
582
static PyObject *Camera_setName( BPy_Camera * self, PyObject * args )
587
if( !PyArg_ParseTuple( args, "s", &name ) )
588
return EXPP_ReturnPyObjError( PyExc_TypeError,
589
"expected string argument" );
591
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
593
rename_id( &self->camera->id, buf );
595
Py_INCREF( Py_None );
599
static PyObject *Camera_setType( BPy_Camera * self, PyObject * args )
603
if( !PyArg_ParseTuple( args, "s", &type ) )
604
return EXPP_ReturnPyObjError( PyExc_TypeError,
605
"expected string argument" );
607
if( strcmp( type, "persp" ) == 0 )
608
self->camera->type = ( short ) EXPP_CAM_TYPE_PERSP;
609
else if( strcmp( type, "ortho" ) == 0 )
610
self->camera->type = ( short ) EXPP_CAM_TYPE_ORTHO;
612
return EXPP_ReturnPyObjError( PyExc_AttributeError,
613
"unknown camera type" );
615
Py_INCREF( Py_None );
594
619
/* This one is 'private'. It is not really a method, just a helper function for
597
622
* the method setType expects a string ('persp' or 'ortho') or an empty
598
623
* argument, this function should receive an int (0 or 1). */
601
Camera_setIntType (BPy_Camera * self, PyObject * args)
625
static PyObject *Camera_setIntType( BPy_Camera * self, PyObject * args )
605
if (!PyArg_ParseTuple (args, "h", &value))
606
return EXPP_ReturnPyObjError (PyExc_TypeError,
607
"expected int argument: 0 or 1");
609
if (value == 0 || value == 1)
610
self->camera->type = value;
612
return EXPP_ReturnPyObjError (PyExc_ValueError,
613
"expected int argument: 0 or 1");
629
if( !PyArg_ParseTuple( args, "h", &value ) )
630
return EXPP_ReturnPyObjError( PyExc_TypeError,
631
"expected int argument: 0 or 1" );
633
if( value == 0 || value == 1 )
634
self->camera->type = value;
636
return EXPP_ReturnPyObjError( PyExc_ValueError,
637
"expected int argument: 0 or 1" );
639
Py_INCREF( Py_None );
620
Camera_setMode (BPy_Camera * self, PyObject * args)
643
static PyObject *Camera_setMode( BPy_Camera * self, PyObject * args )
622
char *mode_str1 = NULL, *mode_str2 = NULL;
625
if (!PyArg_ParseTuple (args, "|ss", &mode_str1, &mode_str2))
626
return EXPP_ReturnPyObjError (PyExc_AttributeError,
627
"expected one or two strings as arguments");
629
if (mode_str1 != NULL)
631
if (strcmp (mode_str1, "showLimits") == 0)
632
flag |= (short) EXPP_CAM_MODE_SHOWLIMITS;
633
else if (strcmp (mode_str1, "showMist") == 0)
634
flag |= (short) EXPP_CAM_MODE_SHOWMIST;
636
return EXPP_ReturnPyObjError (PyExc_AttributeError,
637
"first argument is an unknown camera flag");
639
if (mode_str2 != NULL)
641
if (strcmp (mode_str2, "showLimits") == 0)
642
flag |= (short) EXPP_CAM_MODE_SHOWLIMITS;
643
else if (strcmp (mode_str2, "showMist") == 0)
644
flag |= (short) EXPP_CAM_MODE_SHOWMIST;
646
return EXPP_ReturnPyObjError (PyExc_AttributeError,
647
"second argument is an unknown camera flag");
645
char *mode_str1 = NULL, *mode_str2 = NULL;
648
if( !PyArg_ParseTuple( args, "|ss", &mode_str1, &mode_str2 ) )
649
return EXPP_ReturnPyObjError( PyExc_AttributeError,
650
"expected one or two strings as arguments" );
652
if( mode_str1 != NULL ) {
653
if( strcmp( mode_str1, "showLimits" ) == 0 )
654
flag |= ( short ) EXPP_CAM_MODE_SHOWLIMITS;
655
else if( strcmp( mode_str1, "showMist" ) == 0 )
656
flag |= ( short ) EXPP_CAM_MODE_SHOWMIST;
658
return EXPP_ReturnPyObjError( PyExc_AttributeError,
659
"first argument is an unknown camera flag" );
661
if( mode_str2 != NULL ) {
662
if( strcmp( mode_str2, "showLimits" ) == 0 )
663
flag |= ( short ) EXPP_CAM_MODE_SHOWLIMITS;
664
else if( strcmp( mode_str2, "showMist" ) == 0 )
665
flag |= ( short ) EXPP_CAM_MODE_SHOWMIST;
667
return EXPP_ReturnPyObjError
668
( PyExc_AttributeError,
669
"second argument is an unknown camera flag" );
651
self->camera->flag = flag;
673
self->camera->flag = flag;
675
Py_INCREF( Py_None );
657
679
/* Another helper function, for the same reason.
658
680
* (See comment before Camera_setIntType above). */
661
Camera_setIntMode (BPy_Camera * self, PyObject * args)
665
if (!PyArg_ParseTuple (args, "h", &value))
666
return EXPP_ReturnPyObjError (PyExc_TypeError,
667
"expected int argument in [0,3]");
669
if (value >= 0 && value <= 3)
670
self->camera->flag = value;
672
return EXPP_ReturnPyObjError (PyExc_ValueError,
673
"expected int argument in [0,3]");
680
Camera_setLens (BPy_Camera * self, PyObject * args)
684
if (!PyArg_ParseTuple (args, "f", &value))
685
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
687
self->camera->lens = EXPP_ClampFloat (value,
688
EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
695
Camera_setClipStart (BPy_Camera * self, PyObject * args)
699
if (!PyArg_ParseTuple (args, "f", &value))
700
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
702
self->camera->clipsta = EXPP_ClampFloat (value,
703
EXPP_CAM_CLIPSTART_MIN,
704
EXPP_CAM_CLIPSTART_MAX);
711
Camera_setClipEnd (BPy_Camera * self, PyObject * args)
715
if (!PyArg_ParseTuple (args, "f", &value))
716
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
718
self->camera->clipend = EXPP_ClampFloat (value,
719
EXPP_CAM_CLIPEND_MIN,
720
EXPP_CAM_CLIPEND_MAX);
727
Camera_setDrawSize (BPy_Camera * self, PyObject * args)
731
if (!PyArg_ParseTuple (args, "f", &value))
732
return EXPP_ReturnPyObjError (PyExc_TypeError,
733
"expected a float number as argument");
735
self->camera->drawsize = EXPP_ClampFloat (value,
736
EXPP_CAM_DRAWSIZE_MIN,
737
EXPP_CAM_DRAWSIZE_MAX);
744
Camera_dealloc (BPy_Camera * self)
750
Camera_getAttr (BPy_Camera * self, char *name)
752
PyObject *attr = Py_None;
754
if (strcmp (name, "name") == 0)
755
attr = PyString_FromString (self->camera->id.name + 2);
756
else if (strcmp (name, "type") == 0)
757
attr = PyInt_FromLong (self->camera->type);
758
else if (strcmp (name, "mode") == 0)
759
attr = PyInt_FromLong (self->camera->flag);
760
else if (strcmp (name, "lens") == 0)
761
attr = PyFloat_FromDouble (self->camera->lens);
762
else if (strcmp (name, "clipStart") == 0)
763
attr = PyFloat_FromDouble (self->camera->clipsta);
764
else if (strcmp (name, "clipEnd") == 0)
765
attr = PyFloat_FromDouble (self->camera->clipend);
766
else if (strcmp (name, "drawSize") == 0)
767
attr = PyFloat_FromDouble (self->camera->drawsize);
768
else if (strcmp (name, "ipo") == 0)
770
Ipo *ipo = self->camera->ipo;
772
attr = Ipo_CreatePyObject (ipo);
775
else if (strcmp (name, "Types") == 0)
777
attr = Py_BuildValue ("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP,
778
"ortho", EXPP_CAM_TYPE_ORTHO);
781
else if (strcmp (name, "Modes") == 0)
784
Py_BuildValue ("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS,
785
"showMist", EXPP_CAM_MODE_SHOWMIST);
788
else if (strcmp (name, "__members__") == 0)
790
attr = Py_BuildValue ("[s,s,s,s,s,s,s,s,s,s]",
791
"name", "type", "mode", "lens", "clipStart",
792
"ipo", "clipEnd", "drawSize", "Types", "Modes");
796
return EXPP_ReturnPyObjError (PyExc_MemoryError,
797
"couldn't create PyObject");
800
return attr; /* member attribute found, return it */
802
/* not an attribute, search the methods table */
803
return Py_FindMethod (BPy_Camera_methods, (PyObject *) self, name);
807
Camera_setAttr (BPy_Camera * self, char *name, PyObject * value)
810
PyObject *error = NULL;
682
static PyObject *Camera_setIntMode( BPy_Camera * self, PyObject * args )
686
if( !PyArg_ParseTuple( args, "h", &value ) )
687
return EXPP_ReturnPyObjError( PyExc_TypeError,
688
"expected int argument in [0,3]" );
690
if( value >= 0 && value <= 3 )
691
self->camera->flag = value;
693
return EXPP_ReturnPyObjError( PyExc_ValueError,
694
"expected int argument in [0,3]" );
696
Py_INCREF( Py_None );
700
static PyObject *Camera_setLens( BPy_Camera * self, PyObject * args )
704
if( !PyArg_ParseTuple( args, "f", &value ) )
705
return EXPP_ReturnPyObjError( PyExc_TypeError,
706
"expected float argument" );
708
self->camera->lens = EXPP_ClampFloat( value,
712
Py_INCREF( Py_None );
716
static PyObject *Camera_setScale( BPy_Camera * self, PyObject * args )
720
if( !PyArg_ParseTuple( args, "f", &value ) )
721
return EXPP_ReturnPyObjError( PyExc_TypeError,
722
"expected float argument" );
724
self->camera->ortho_scale = EXPP_ClampFloat( value,
726
EXPP_CAM_SCALE_MAX );
728
Py_INCREF( Py_None );
732
static PyObject *Camera_setClipStart( BPy_Camera * self, PyObject * args )
736
if( !PyArg_ParseTuple( args, "f", &value ) )
737
return EXPP_ReturnPyObjError( PyExc_TypeError,
738
"expected float argument" );
740
self->camera->clipsta = EXPP_ClampFloat( value,
741
EXPP_CAM_CLIPSTART_MIN,
742
EXPP_CAM_CLIPSTART_MAX );
744
Py_INCREF( Py_None );
748
static PyObject *Camera_setClipEnd( BPy_Camera * self, PyObject * args )
752
if( !PyArg_ParseTuple( args, "f", &value ) )
753
return EXPP_ReturnPyObjError( PyExc_TypeError,
754
"expected float argument" );
756
self->camera->clipend = EXPP_ClampFloat( value,
757
EXPP_CAM_CLIPEND_MIN,
758
EXPP_CAM_CLIPEND_MAX );
760
Py_INCREF( Py_None );
764
static PyObject *Camera_setDrawSize( BPy_Camera * self, PyObject * args )
768
if( !PyArg_ParseTuple( args, "f", &value ) )
769
return EXPP_ReturnPyObjError( PyExc_TypeError,
770
"expected a float number as argument" );
772
self->camera->drawsize = EXPP_ClampFloat( value,
773
EXPP_CAM_DRAWSIZE_MIN,
774
EXPP_CAM_DRAWSIZE_MAX );
776
Py_INCREF( Py_None );
780
/* cam.addScriptLink */
781
static PyObject *Camera_addScriptLink( BPy_Camera * self, PyObject * args )
783
Camera *cam = self->camera;
784
ScriptLink *slink = NULL;
786
slink = &( cam )->scriptlink;
788
return EXPP_addScriptLink( slink, args, 0 );
791
/* cam.clearScriptLinks */
792
static PyObject *Camera_clearScriptLinks( BPy_Camera * self, PyObject * args )
794
Camera *cam = self->camera;
795
ScriptLink *slink = NULL;
797
slink = &( cam )->scriptlink;
799
return EXPP_clearScriptLinks( slink, args );
802
/* cam.getScriptLinks */
803
static PyObject *Camera_getScriptLinks( BPy_Camera * self, PyObject * args )
805
Camera *cam = self->camera;
806
ScriptLink *slink = NULL;
807
PyObject *ret = NULL;
809
slink = &( cam )->scriptlink;
811
ret = EXPP_getScriptLinks( slink, args, 0 );
819
static void Camera_dealloc( BPy_Camera * self )
821
PyObject_DEL( self );
824
static PyObject *Camera_getAttr( BPy_Camera * self, char *name )
826
PyObject *attr = Py_None;
828
if( strcmp( name, "name" ) == 0 )
829
attr = PyString_FromString( self->camera->id.name + 2 );
830
else if( strcmp( name, "type" ) == 0 )
831
attr = PyInt_FromLong( self->camera->type );
832
else if( strcmp( name, "mode" ) == 0 )
833
attr = PyInt_FromLong( self->camera->flag );
834
else if( strcmp( name, "lens" ) == 0 )
835
attr = PyFloat_FromDouble( self->camera->lens );
836
else if( strcmp( name, "scale" ) == 0 )
837
attr = PyFloat_FromDouble( self->camera->ortho_scale );
838
else if( strcmp( name, "clipStart" ) == 0 )
839
attr = PyFloat_FromDouble( self->camera->clipsta );
840
else if( strcmp( name, "clipEnd" ) == 0 )
841
attr = PyFloat_FromDouble( self->camera->clipend );
842
else if( strcmp( name, "drawSize" ) == 0 )
843
attr = PyFloat_FromDouble( self->camera->drawsize );
844
else if( strcmp( name, "users" ) == 0 )
845
attr = PyInt_FromLong( self->camera->id.us );
846
else if( strcmp( name, "ipo" ) == 0 ) {
847
Ipo *ipo = self->camera->ipo;
849
attr = Ipo_CreatePyObject( ipo );
852
else if( strcmp( name, "Types" ) == 0 ) {
853
attr = Py_BuildValue( "{s:h,s:h}", "persp",
854
EXPP_CAM_TYPE_PERSP, "ortho",
855
EXPP_CAM_TYPE_ORTHO );
858
else if( strcmp( name, "Modes" ) == 0 ) {
859
attr = Py_BuildValue( "{s:h,s:h}", "showLimits",
860
EXPP_CAM_MODE_SHOWLIMITS, "showMist",
861
EXPP_CAM_MODE_SHOWMIST );
864
else if( strcmp( name, "__members__" ) == 0 ) {
865
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s,s]",
866
"name", "type", "mode", "lens", "scale",
867
"clipStart", "ipo", "clipEnd",
868
"drawSize", "Types", "Modes", "users" );
872
return EXPP_ReturnPyObjError( PyExc_MemoryError,
873
"couldn't create PyObject" );
875
if( attr != Py_None )
876
return attr; /* member attribute found, return it */
878
/* not an attribute, search the methods table */
879
return Py_FindMethod( BPy_Camera_methods, ( PyObject * ) self, name );
882
static int Camera_setAttr( BPy_Camera * self, char *name, PyObject * value )
885
PyObject *error = NULL;
812
887
/* We're playing a trick on the Python API users here. Even if they use
813
888
* Camera.member = val instead of Camera.setMember(val), we end up using the