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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Camera.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: Camera.c,v 1.34 2005/05/27 05:39:40 ianwill Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
24
25
 *
25
26
 * This is a new part of Blender.
26
27
 *
27
 
 * Contributor(s): Willian P. Germano
 
28
 * Contributor(s): Willian P. Germano, Johnny Matthews, Ken Hughes
28
29
 *
29
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
31
*/
34
35
#include <BKE_object.h>
35
36
#include <BKE_library.h>
36
37
#include <BLI_blenlib.h>
 
38
#include <BIF_editview.h>
 
39
#include <BSE_editipo.h>
 
40
#include <BIF_space.h>
 
41
#include <mydevice.h>
37
42
 
38
43
#include <Python.h>
39
 
#include <DNA_camera_types.h>
 
44
 
40
45
#include "constant.h"
41
46
#include "gen_utils.h"
42
 
#include "modules.h"
43
47
 
44
48
#include "Camera.h"
45
 
 
 
49
#include "Ipo.h"
 
50
 
 
51
 
 
52
#define IPOKEY_LENS 0
 
53
#define IPOKEY_CLIPPING 1
46
54
 
47
55
/*****************************************************************************/
48
56
/* Python API function prototypes for the Camera module.                     */
49
57
/*****************************************************************************/
50
 
static PyObject *M_Camera_New (PyObject * self, PyObject * args,
51
 
                               PyObject * keywords);
52
 
static PyObject *M_Camera_Get (PyObject * self, PyObject * args);
 
58
static PyObject *M_Camera_New( PyObject * self, PyObject * args,
 
59
                               PyObject * keywords );
 
60
static PyObject *M_Camera_Get( PyObject * self, PyObject * args );
53
61
 
54
62
/*****************************************************************************/
55
63
/* The following string definitions are used for documentation strings.      */
64
72
\n\
65
73
  from Blender import Camera, Object, Scene\n\
66
74
  c = Camera.New('ortho')      # create new ortho camera data\n\
67
 
  c.lens = 35.0                # set lens value\n\
 
75
  c.scale = 6.0                # set scale value\n\
68
76
  cur = Scene.getCurrent()     # get current Scene\n\
69
77
  ob = Object.New('Camera')    # make camera object\n\
70
78
  ob.link(c)                   # link camera data with this object\n\
72
80
  cur.setCurrentCamera(ob)     # make this camera the active";
73
81
 
74
82
static char M_Camera_New_doc[] =
75
 
  "Camera.New (type = 'persp', name = 'CamData'):\n\
 
83
        "Camera.New (type = 'persp', name = 'CamData'):\n\
76
84
        Return a new Camera Data object with the given type and name.";
77
85
 
78
86
static char M_Camera_Get_doc[] = "Camera.Get (name = None):\n\
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,
88
 
   M_Camera_New_doc},
89
 
  {"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
90
 
  {"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
91
 
  {NULL, NULL, 0, NULL}
 
95
        {"New", ( PyCFunction ) M_Camera_New, METH_VARARGS | METH_KEYWORDS,
 
96
         M_Camera_New_doc},
 
97
        {"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
 
98
        {"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
 
99
        {NULL, NULL, 0, NULL}
92
100
};
93
101
 
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 );
 
130
 
 
131
Camera *GetCameraByName( char *name );
 
132
 
116
133
 
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,
 
189
         METH_NOARGS,
 
190
         "() - Delete all scriptlinks from this camera.\n"
 
191
         "([s1<,s2,s3...>]) - Delete specified scriptlinks from this camera."},
 
192
        {NULL, NULL, 0, NULL}
158
193
};
159
194
 
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 );
168
203
 
169
204
 
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 */
177
 
  0,                            /* tp_itemsize */
178
 
  /* methods */
179
 
  (destructor) Camera_dealloc,  /* tp_dealloc */
180
 
  0,                            /* tp_print */
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 */
188
 
  0,                            /* tp_as_hash */
189
 
  0, 0, 0, 0, 0, 0,
190
 
  0,                            /* tp_doc */
191
 
  0, 0, 0, 0, 0, 0,
192
 
  BPy_Camera_methods,           /* tp_methods */
193
 
  0,                            /* tp_members */
 
209
        PyObject_HEAD_INIT( NULL ) /* required macro */ 
 
210
        0,      /* ob_size */
 
211
        "Blender Camera",       /* tp_name */
 
212
        sizeof( BPy_Camera ),   /* tp_basicsize */
 
213
        0,                      /* tp_itemsize */
 
214
        /* methods */
 
215
        ( destructor ) Camera_dealloc,  /* tp_dealloc */
 
216
        0,                      /* tp_print */
 
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 */
 
224
        0,                      /* tp_as_hash */
 
225
        0, 0, 0, 0, 0, 0,
 
226
        0,                      /* tp_doc */
 
227
        0, 0, 0, 0, 0, 0,
 
228
        BPy_Camera_methods,     /* tp_methods */
 
229
        0,                      /* tp_members */
 
230
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
194
231
};
195
232
 
196
 
static PyObject *
197
 
M_Camera_New (PyObject * self, PyObject * args, PyObject * kwords)
198
 
{
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 */
204
 
  char buf[21];
205
 
 
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");
212
 
 
213
 
  blcam = add_camera ();        /* first create the Camera Data in Blender */
214
 
 
215
 
  if (blcam)                    /* now create the wrapper obj in Python */
216
 
    pycam = Camera_CreatePyObject (blcam);
217
 
  else
218
 
    return EXPP_ReturnPyObjError (PyExc_RuntimeError,
219
 
                                  "couldn't create Camera Data in Blender");
220
 
 
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 */
224
 
 
225
 
  if (pycam == NULL)
226
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
227
 
                                  "couldn't create Camera PyObject");
228
 
 
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;
234
 
  else
235
 
    return EXPP_ReturnPyObjError (PyExc_AttributeError,
236
 
                                  "unknown camera type");
237
 
 
238
 
  if (strcmp (name_str, "CamData") == 0)
239
 
    return pycam;
240
 
  else
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 */
244
 
    }
245
 
 
246
 
  return pycam;
247
 
}
248
 
 
249
 
static PyObject *
250
 
M_Camera_Get (PyObject * self, PyObject * args)
251
 
{
252
 
  char *name = NULL;
253
 
  Camera *cam_iter;
254
 
 
255
 
  if (!PyArg_ParseTuple (args, "|s", &name))
256
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
257
 
                                  "expected string argument (or nothing)");
258
 
 
259
 
  cam_iter = G.main->camera.first;
260
 
 
261
 
  if (name)
262
 
    {                           /* (name) - Search camera by name */
263
 
 
264
 
      PyObject *wanted_cam = NULL;
265
 
 
266
 
      while (cam_iter && !wanted_cam)
267
 
        {
268
 
 
269
 
          if (strcmp (name, cam_iter->id.name + 2) == 0)
270
 
            {
271
 
              wanted_cam = Camera_CreatePyObject (cam_iter);
272
 
              break;
273
 
            }
274
 
 
275
 
          cam_iter = cam_iter->id.next;
276
 
        }
277
 
 
278
 
      if (!wanted_cam)
279
 
        {                       /* Requested camera doesn't exist */
280
 
          char error_msg[64];
281
 
          PyOS_snprintf (error_msg, sizeof (error_msg),
282
 
                         "Camera \"%s\" not found", name);
283
 
          return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
284
 
        }
285
 
 
286
 
      return wanted_cam;
287
 
    }
288
 
 
289
 
  else
290
 
    {                           /* () - return a list of wrappers for all cameras in the scene */
291
 
      int index = 0;
292
 
      PyObject *cam_pylist, *pyobj;
293
 
 
294
 
      cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
295
 
 
296
 
      if (!cam_pylist)
297
 
        return PythonReturnErrorObject (PyExc_MemoryError,
298
 
                                        "couldn't create PyList");
299
 
 
300
 
      while (cam_iter)
301
 
        {
302
 
          pyobj = Camera_CreatePyObject (cam_iter);
303
 
 
304
 
          if (!pyobj)
305
 
            return PythonReturnErrorObject (PyExc_MemoryError,
306
 
                                            "couldn't create Camera PyObject");
307
 
 
308
 
          PyList_SET_ITEM (cam_pylist, index, pyobj);
309
 
 
310
 
          cam_iter = cam_iter->id.next;
311
 
          index++;
312
 
        }
313
 
 
314
 
      return cam_pylist;
315
 
    }
316
 
}
317
 
 
318
 
PyObject *
319
 
Camera_Init (void)
320
 
{
321
 
  PyObject *submodule;
322
 
 
323
 
  Camera_Type.ob_type = &PyType_Type;
324
 
 
325
 
  submodule = Py_InitModule3 ("Blender.Camera",
326
 
                              M_Camera_methods, M_Camera_doc);
327
 
 
328
 
  return submodule;
 
233
static PyObject *M_Camera_New( PyObject * self, PyObject * args,
 
234
                               PyObject * kwords )
 
235
{
 
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 */
 
241
        char buf[21];
 
242
 
 
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" );
 
249
 
 
250
        blcam = add_camera(  ); /* first create the Camera Data in Blender */
 
251
 
 
252
        if( blcam )             /* now create the wrapper obj in Python */
 
253
                pycam = Camera_CreatePyObject( blcam );
 
254
        else
 
255
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
256
                                              "couldn't create Camera Data in Blender" );
 
257
 
 
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 */
 
261
 
 
262
        if( pycam == NULL )
 
263
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
264
                                              "couldn't create Camera PyObject" );
 
265
 
 
266
        if( strcmp( type_str, "persp" ) == 0 )
 
267
                /* default, no need to set, so */
 
268
                /*blcam->type = (short)EXPP_CAM_TYPE_PERSP */
 
269
                ;
 
270
        /* we comment this line */
 
271
        else if( strcmp( type_str, "ortho" ) == 0 )
 
272
                blcam->type = ( short ) EXPP_CAM_TYPE_ORTHO;
 
273
        else
 
274
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
275
                                              "unknown camera type" );
 
276
 
 
277
        if( strcmp( name_str, "CamData" ) == 0 )
 
278
                return pycam;
 
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 */
 
282
        }
 
283
 
 
284
        return pycam;
 
285
}
 
286
 
 
287
static PyObject *M_Camera_Get( PyObject * self, PyObject * args )
 
288
{
 
289
        char *name = NULL;
 
290
        Camera *cam_iter;
 
291
 
 
292
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
293
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
294
                                              "expected string argument (or nothing)" );
 
295
 
 
296
        cam_iter = G.main->camera.first;
 
297
 
 
298
        if( name ) {            /* (name) - Search camera by name */
 
299
 
 
300
                PyObject *wanted_cam = NULL;
 
301
 
 
302
                while( cam_iter && !wanted_cam ) {
 
303
 
 
304
                        if( strcmp( name, cam_iter->id.name + 2 ) == 0 ) {
 
305
                                wanted_cam = Camera_CreatePyObject( cam_iter );
 
306
                                break;
 
307
                        }
 
308
 
 
309
                        cam_iter = cam_iter->id.next;
 
310
                }
 
311
 
 
312
                if( !wanted_cam ) {     /* Requested camera doesn't exist */
 
313
                        char error_msg[64];
 
314
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
 
315
                                       "Camera \"%s\" not found", name );
 
316
                        return EXPP_ReturnPyObjError( PyExc_NameError,
 
317
                                                      error_msg );
 
318
                }
 
319
 
 
320
                return wanted_cam;
 
321
        }
 
322
 
 
323
        else {                  /* () - return a list of wrappers for all cameras in the scene */
 
324
                int index = 0;
 
325
                PyObject *cam_pylist, *pyobj;
 
326
 
 
327
                cam_pylist =
 
328
                        PyList_New( BLI_countlist( &( G.main->camera ) ) );
 
329
 
 
330
                if( !cam_pylist )
 
331
                        return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
332
                                                      "couldn't create PyList" );
 
333
 
 
334
                while( cam_iter ) {
 
335
                        pyobj = Camera_CreatePyObject( cam_iter );
 
336
 
 
337
                        if( !pyobj )
 
338
                                return EXPP_ReturnPyObjError
 
339
                                        ( PyExc_MemoryError,
 
340
                                          "couldn't create Camera PyObject" );
 
341
 
 
342
                        PyList_SET_ITEM( cam_pylist, index, pyobj );
 
343
 
 
344
                        cam_iter = cam_iter->id.next;
 
345
                        index++;
 
346
                }
 
347
 
 
348
                return cam_pylist;
 
349
        }
 
350
}
 
351
 
 
352
PyObject *Camera_Init( void )
 
353
{
 
354
        PyObject *submodule;
 
355
 
 
356
        Camera_Type.ob_type = &PyType_Type;
 
357
 
 
358
        submodule = Py_InitModule3( "Blender.Camera",
 
359
                                    M_Camera_methods, M_Camera_doc );
 
360
 
 
361
        PyModule_AddIntConstant( submodule, "LENS",     IPOKEY_LENS );
 
362
        PyModule_AddIntConstant( submodule, "CLIPPING", IPOKEY_CLIPPING );
 
363
 
 
364
        return submodule;
329
365
}
330
366
 
331
367
/* Three Python Camera_Type helper functions needed by the Object module: */
332
368
 
333
 
PyObject *
334
 
Camera_CreatePyObject (Camera * cam)
335
 
{
336
 
  BPy_Camera *pycam;
337
 
 
338
 
  pycam = (BPy_Camera *) PyObject_NEW (BPy_Camera, &Camera_Type);
339
 
 
340
 
  if (!pycam)
341
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
342
 
                                  "couldn't create BPy_Camera PyObject");
343
 
 
344
 
  pycam->camera = cam;
345
 
 
346
 
  return (PyObject *) pycam;
347
 
}
348
 
 
349
 
int
350
 
Camera_CheckPyObject (PyObject * pyobj)
351
 
{
352
 
  return (pyobj->ob_type == &Camera_Type);
353
 
}
354
 
 
355
 
Camera *
356
 
Camera_FromPyObject (PyObject * pyobj)
357
 
{
358
 
  return ((BPy_Camera *) pyobj)->camera;
359
 
}
360
 
 
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  */
367
 
/*                                                      name is found.                                                                                                                                                                                   */
368
 
/*****************************************************************************/
369
 
Camera *
370
 
GetCameraByName (char *name)
371
 
{
372
 
  Camera *cam_iter;
373
 
 
374
 
  cam_iter = G.main->camera.first;
375
 
  while (cam_iter)
376
 
    {
377
 
      if (StringEqual (name, GetIdName (&(cam_iter->id))))
378
 
        {
379
 
          return (cam_iter);
380
 
        }
381
 
      cam_iter = cam_iter->id.next;
382
 
    }
383
 
 
384
 
  /* There is no camera with the given name */
385
 
  return (NULL);
386
 
}
387
 
 
388
 
/*****************************************************************************/
389
 
/* Python BPy_Camera methods:                                                                                                                                                                                            */
390
 
/*****************************************************************************/
391
 
 
392
 
static PyObject *
393
 
Camera_getIpo (BPy_Camera * self)
394
 
{
395
 
  struct Ipo *ipo = self->camera->ipo;
396
 
 
397
 
  if (!ipo)
398
 
    {
399
 
      Py_INCREF (Py_None);
400
 
      return Py_None;
401
 
    }
402
 
 
403
 
  return Ipo_CreatePyObject (ipo);
404
 
}
405
 
 
406
 
 
407
 
 
408
 
 
409
 
 
410
 
 
411
 
static PyObject *
412
 
Camera_getName (BPy_Camera * self)
413
 
{
414
 
 
415
 
  PyObject *attr = PyString_FromString (self->camera->id.name + 2);
416
 
 
417
 
  if (attr)
418
 
    return attr;
419
 
 
420
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
421
 
                                "couldn't get Camera.name attribute");
422
 
}
423
 
 
424
 
static PyObject *
425
 
Camera_getType (BPy_Camera * self)
426
 
{
427
 
  PyObject *attr = PyInt_FromLong (self->camera->type);
428
 
 
429
 
  if (attr)
430
 
    return attr;
431
 
 
432
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
433
 
                                "couldn't get Camera.type attribute");
434
 
}
435
 
 
436
 
static PyObject *
437
 
Camera_getMode (BPy_Camera * self)
438
 
{
439
 
  PyObject *attr = PyInt_FromLong (self->camera->flag);
440
 
 
441
 
  if (attr)
442
 
    return attr;
443
 
 
444
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
445
 
                                "couldn't get Camera.Mode attribute");
446
 
}
447
 
 
448
 
static PyObject *
449
 
Camera_getLens (BPy_Camera * self)
450
 
{
451
 
  PyObject *attr = PyFloat_FromDouble (self->camera->lens);
452
 
 
453
 
  if (attr)
454
 
    return attr;
455
 
 
456
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
457
 
                                "couldn't get Camera.lens attribute");
458
 
}
459
 
 
460
 
static PyObject *
461
 
Camera_getClipStart (BPy_Camera * self)
462
 
{
463
 
  PyObject *attr = PyFloat_FromDouble (self->camera->clipsta);
464
 
 
465
 
  if (attr)
466
 
    return attr;
467
 
 
468
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
469
 
                                "couldn't get Camera.clipStart attribute");
470
 
}
471
 
 
472
 
static PyObject *
473
 
Camera_getClipEnd (BPy_Camera * self)
474
 
{
475
 
  PyObject *attr = PyFloat_FromDouble (self->camera->clipend);
476
 
 
477
 
  if (attr)
478
 
    return attr;
479
 
 
480
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
481
 
                                "couldn't get Camera.clipEnd attribute");
482
 
}
483
 
 
484
 
static PyObject *
485
 
Camera_getDrawSize (BPy_Camera * self)
486
 
{
487
 
  PyObject *attr = PyFloat_FromDouble (self->camera->drawsize);
488
 
 
489
 
  if (attr)
490
 
    return attr;
491
 
 
492
 
  return EXPP_ReturnPyObjError (PyExc_RuntimeError,
493
 
                                "couldn't get Camera.drawSize attribute");
494
 
}
495
 
 
496
 
 
497
 
 
498
 
static PyObject *
499
 
Camera_setIpo (BPy_Camera * self, PyObject * args)
500
 
{
501
 
  PyObject *pyipo = 0;
502
 
  Ipo *ipo = NULL;
503
 
  Ipo *oldipo;
504
 
 
505
 
  if (!PyArg_ParseTuple (args, "O!", &Ipo_Type, &pyipo))
506
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
507
 
                                  "expected Ipo as argument");
508
 
 
509
 
  ipo = Ipo_FromPyObject (pyipo);
510
 
 
511
 
  if (!ipo)
512
 
    return EXPP_ReturnPyObjError (PyExc_RuntimeError, "null ipo!");
513
 
 
514
 
  if (ipo->blocktype != ID_CA)
515
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
516
 
                                  "this ipo is not a camera data ipo");
517
 
 
518
 
  oldipo = self->camera->ipo;
519
 
  if (oldipo)
520
 
    {
521
 
      ID *id = &oldipo->id;
522
 
      if (id->us > 0)
523
 
        id->us--;
524
 
    }
525
 
 
526
 
  ((ID *) & ipo->id)->us++;
527
 
 
528
 
  self->camera->ipo = ipo;
529
 
 
530
 
  Py_INCREF (Py_None);
531
 
  return Py_None;
532
 
}
533
 
 
534
 
static PyObject *
535
 
Camera_clearIpo (BPy_Camera * self)
536
 
{
537
 
  Camera *cam = self->camera;
538
 
  Ipo *ipo = (Ipo *) cam->ipo;
539
 
 
540
 
  if (ipo)
541
 
    {
542
 
      ID *id = &ipo->id;
543
 
      if (id->us > 0)
544
 
        id->us--;
545
 
      cam->ipo = NULL;
546
 
 
547
 
      Py_INCREF (Py_True);
548
 
      return Py_True;
549
 
    }
550
 
 
551
 
  Py_INCREF (Py_False);         /* no ipo found */
552
 
  return Py_False;
553
 
}
554
 
 
555
 
static PyObject *
556
 
Camera_setName (BPy_Camera * self, PyObject * args)
557
 
{
558
 
  char *name;
559
 
  char buf[21];
560
 
 
561
 
  if (!PyArg_ParseTuple (args, "s", &name))
562
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
563
 
                                  "expected string argument");
564
 
 
565
 
  PyOS_snprintf (buf, sizeof (buf), "%s", name);
566
 
 
567
 
  rename_id (&self->camera->id, buf);
568
 
 
569
 
  Py_INCREF (Py_None);
570
 
  return Py_None;
571
 
}
572
 
 
573
 
static PyObject *
574
 
Camera_setType (BPy_Camera * self, PyObject * args)
575
 
{
576
 
  char *type;
577
 
 
578
 
  if (!PyArg_ParseTuple (args, "s", &type))
579
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
580
 
                                  "expected string argument");
581
 
 
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;
586
 
  else
587
 
    return EXPP_ReturnPyObjError (PyExc_AttributeError,
588
 
                                  "unknown camera type");
589
 
 
590
 
  Py_INCREF (Py_None);
591
 
  return Py_None;
 
369
PyObject *Camera_CreatePyObject( Camera * cam )
 
370
{
 
371
        BPy_Camera *pycam;
 
372
 
 
373
        pycam = ( BPy_Camera * ) PyObject_NEW( BPy_Camera, &Camera_Type );
 
374
 
 
375
        if( !pycam )
 
376
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
377
                                              "couldn't create BPy_Camera PyObject" );
 
378
 
 
379
        pycam->camera = cam;
 
380
 
 
381
        return ( PyObject * ) pycam;
 
382
}
 
383
 
 
384
int Camera_CheckPyObject( PyObject * pyobj )
 
385
{
 
386
        return ( pyobj->ob_type == &Camera_Type );
 
387
}
 
388
 
 
389
Camera *Camera_FromPyObject( PyObject * pyobj )
 
390
{
 
391
        return ( ( BPy_Camera * ) pyobj )->camera;
 
392
}
 
393
 
 
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  */
 
400
/*      name is found.                                                      */
 
401
/*****************************************************************************/
 
402
Camera *GetCameraByName( char *name )
 
403
{
 
404
        Camera *cam_iter;
 
405
 
 
406
        cam_iter = G.main->camera.first;
 
407
        while( cam_iter ) {
 
408
                if( StringEqual( name, GetIdName( &( cam_iter->id ) ) ) ) {
 
409
                        return ( cam_iter );
 
410
                }
 
411
                cam_iter = cam_iter->id.next;
 
412
        }
 
413
 
 
414
        /* There is no camera with the given name */
 
415
        return ( NULL );
 
416
}
 
417
 
 
418
/*****************************************************************************/
 
419
/* Python BPy_Camera methods:                                               */
 
420
/*****************************************************************************/
 
421
 
 
422
static PyObject *Camera_getIpo( BPy_Camera * self )
 
423
{
 
424
        struct Ipo *ipo = self->camera->ipo;
 
425
 
 
426
        if( !ipo ) {
 
427
                Py_INCREF( Py_None );
 
428
                return Py_None;
 
429
        }
 
430
 
 
431
        return Ipo_CreatePyObject( ipo );
 
432
}
 
433
 
 
434
 
 
435
 
 
436
 
 
437
 
 
438
 
 
439
static PyObject *Camera_getName( BPy_Camera * self )
 
440
{
 
441
 
 
442
        PyObject *attr = PyString_FromString( self->camera->id.name + 2 );
 
443
 
 
444
        if( attr )
 
445
                return attr;
 
446
 
 
447
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
448
                                      "couldn't get Camera.name attribute" );
 
449
}
 
450
 
 
451
static PyObject *Camera_getType( BPy_Camera * self )
 
452
{
 
453
        PyObject *attr = PyInt_FromLong( self->camera->type );
 
454
 
 
455
        if( attr )
 
456
                return attr;
 
457
 
 
458
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
459
                                      "couldn't get Camera.type attribute" );
 
460
}
 
461
 
 
462
static PyObject *Camera_getMode( BPy_Camera * self )
 
463
{
 
464
        PyObject *attr = PyInt_FromLong( self->camera->flag );
 
465
 
 
466
        if( attr )
 
467
                return attr;
 
468
 
 
469
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
470
                                      "couldn't get Camera.Mode attribute" );
 
471
}
 
472
 
 
473
static PyObject *Camera_getLens( BPy_Camera * self )
 
474
{
 
475
        PyObject *attr = PyFloat_FromDouble( self->camera->lens );
 
476
 
 
477
        if( attr )
 
478
                return attr;
 
479
 
 
480
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
481
                                      "couldn't get Camera.lens attribute" );
 
482
}
 
483
 
 
484
static PyObject *Camera_getScale( BPy_Camera * self )
 
485
{
 
486
        PyObject *attr = PyFloat_FromDouble( self->camera->ortho_scale );
 
487
 
 
488
        if( attr )
 
489
                return attr;
 
490
 
 
491
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
492
                                      "couldn't get Camera.scale attribute" );
 
493
}
 
494
 
 
495
static PyObject *Camera_getClipStart( BPy_Camera * self )
 
496
{
 
497
        PyObject *attr = PyFloat_FromDouble( self->camera->clipsta );
 
498
 
 
499
        if( attr )
 
500
                return attr;
 
501
 
 
502
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
503
                                      "couldn't get Camera.clipStart attribute" );
 
504
}
 
505
 
 
506
static PyObject *Camera_getClipEnd( BPy_Camera * self )
 
507
{
 
508
        PyObject *attr = PyFloat_FromDouble( self->camera->clipend );
 
509
 
 
510
        if( attr )
 
511
                return attr;
 
512
 
 
513
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
514
                                      "couldn't get Camera.clipEnd attribute" );
 
515
}
 
516
 
 
517
static PyObject *Camera_getDrawSize( BPy_Camera * self )
 
518
{
 
519
        PyObject *attr = PyFloat_FromDouble( self->camera->drawsize );
 
520
 
 
521
        if( attr )
 
522
                return attr;
 
523
 
 
524
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
525
                                      "couldn't get Camera.drawSize attribute" );
 
526
}
 
527
 
 
528
 
 
529
 
 
530
static PyObject *Camera_setIpo( BPy_Camera * self, PyObject * args )
 
531
{
 
532
        PyObject *pyipo = 0;
 
533
        Ipo *ipo = NULL;
 
534
        Ipo *oldipo;
 
535
 
 
536
        if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) )
 
537
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
538
                                              "expected Ipo as argument" );
 
539
 
 
540
        ipo = Ipo_FromPyObject( pyipo );
 
541
 
 
542
        if( !ipo )
 
543
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
544
                                              "null ipo!" );
 
545
 
 
546
        if( ipo->blocktype != ID_CA )
 
547
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
548
                                              "this ipo is not a camera data ipo" );
 
549
 
 
550
        oldipo = self->camera->ipo;
 
551
        if( oldipo ) {
 
552
                ID *id = &oldipo->id;
 
553
                if( id->us > 0 )
 
554
                        id->us--;
 
555
        }
 
556
 
 
557
        ( ( ID * ) & ipo->id )->us++;
 
558
 
 
559
        self->camera->ipo = ipo;
 
560
 
 
561
        Py_INCREF( Py_None );
 
562
        return Py_None;
 
563
}
 
564
 
 
565
static PyObject *Camera_clearIpo( BPy_Camera * self )
 
566
{
 
567
        Camera *cam = self->camera;
 
568
        Ipo *ipo = ( Ipo * ) cam->ipo;
 
569
 
 
570
        if( ipo ) {
 
571
                ID *id = &ipo->id;
 
572
                if( id->us > 0 )
 
573
                        id->us--;
 
574
                cam->ipo = NULL;
 
575
 
 
576
                return EXPP_incr_ret_True();
 
577
        }
 
578
 
 
579
        return EXPP_incr_ret_False(); /* no ipo found */
 
580
}
 
581
 
 
582
static PyObject *Camera_setName( BPy_Camera * self, PyObject * args )
 
583
{
 
584
        char *name;
 
585
        char buf[21];
 
586
 
 
587
        if( !PyArg_ParseTuple( args, "s", &name ) )
 
588
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
589
                                              "expected string argument" );
 
590
 
 
591
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
 
592
 
 
593
        rename_id( &self->camera->id, buf );
 
594
 
 
595
        Py_INCREF( Py_None );
 
596
        return Py_None;
 
597
}
 
598
 
 
599
static PyObject *Camera_setType( BPy_Camera * self, PyObject * args )
 
600
{
 
601
        char *type;
 
602
 
 
603
        if( !PyArg_ParseTuple( args, "s", &type ) )
 
604
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
605
                                              "expected string argument" );
 
606
 
 
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;
 
611
        else
 
612
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
613
                                              "unknown camera type" );
 
614
 
 
615
        Py_INCREF( Py_None );
 
616
        return Py_None;
592
617
}
593
618
 
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). */
599
624
 
600
 
static PyObject *
601
 
Camera_setIntType (BPy_Camera * self, PyObject * args)
 
625
static PyObject *Camera_setIntType( BPy_Camera * self, PyObject * args )
602
626
{
603
 
  short value;
604
 
 
605
 
  if (!PyArg_ParseTuple (args, "h", &value))
606
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
607
 
                                  "expected int argument: 0 or 1");
608
 
 
609
 
  if (value == 0 || value == 1)
610
 
    self->camera->type = value;
611
 
  else
612
 
    return EXPP_ReturnPyObjError (PyExc_ValueError,
613
 
                                  "expected int argument: 0 or 1");
614
 
 
615
 
  Py_INCREF (Py_None);
616
 
  return Py_None;
 
627
        short value;
 
628
 
 
629
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
630
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
631
                                              "expected int argument: 0 or 1" );
 
632
 
 
633
        if( value == 0 || value == 1 )
 
634
                self->camera->type = value;
 
635
        else
 
636
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
637
                                              "expected int argument: 0 or 1" );
 
638
 
 
639
        Py_INCREF( Py_None );
 
640
        return Py_None;
617
641
}
618
642
 
619
 
static PyObject *
620
 
Camera_setMode (BPy_Camera * self, PyObject * args)
 
643
static PyObject *Camera_setMode( BPy_Camera * self, PyObject * args )
621
644
{
622
 
  char *mode_str1 = NULL, *mode_str2 = NULL;
623
 
  short flag = 0;
624
 
 
625
 
  if (!PyArg_ParseTuple (args, "|ss", &mode_str1, &mode_str2))
626
 
    return EXPP_ReturnPyObjError (PyExc_AttributeError,
627
 
                                  "expected one or two strings as arguments");
628
 
 
629
 
  if (mode_str1 != NULL)
630
 
    {
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;
635
 
      else
636
 
        return EXPP_ReturnPyObjError (PyExc_AttributeError,
637
 
                                      "first argument is an unknown camera flag");
638
 
 
639
 
      if (mode_str2 != NULL)
640
 
        {
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;
645
 
          else
646
 
            return EXPP_ReturnPyObjError (PyExc_AttributeError,
647
 
                                          "second argument is an unknown camera flag");
 
645
        char *mode_str1 = NULL, *mode_str2 = NULL;
 
646
        short flag = 0;
 
647
 
 
648
        if( !PyArg_ParseTuple( args, "|ss", &mode_str1, &mode_str2 ) )
 
649
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
650
                                              "expected one or two strings as arguments" );
 
651
 
 
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;
 
657
                else
 
658
                        return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
659
                                                      "first argument is an unknown camera flag" );
 
660
 
 
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;
 
666
                        else
 
667
                                return EXPP_ReturnPyObjError
 
668
                                        ( PyExc_AttributeError,
 
669
                                          "second argument is an unknown camera flag" );
 
670
                }
648
671
        }
649
 
    }
650
 
 
651
 
  self->camera->flag = flag;
652
 
 
653
 
  Py_INCREF (Py_None);
654
 
  return Py_None;
 
672
 
 
673
        self->camera->flag = flag;
 
674
 
 
675
        Py_INCREF( Py_None );
 
676
        return Py_None;
655
677
}
656
678
 
657
679
/* Another helper function, for the same reason.
658
680
 * (See comment before Camera_setIntType above). */
659
681
 
660
 
static PyObject *
661
 
Camera_setIntMode (BPy_Camera * self, PyObject * args)
662
 
{
663
 
  short value;
664
 
 
665
 
  if (!PyArg_ParseTuple (args, "h", &value))
666
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
667
 
                                  "expected int argument in [0,3]");
668
 
 
669
 
  if (value >= 0 && value <= 3)
670
 
    self->camera->flag = value;
671
 
  else
672
 
    return EXPP_ReturnPyObjError (PyExc_ValueError,
673
 
                                  "expected int argument in [0,3]");
674
 
 
675
 
  Py_INCREF (Py_None);
676
 
  return Py_None;
677
 
}
678
 
 
679
 
static PyObject *
680
 
Camera_setLens (BPy_Camera * self, PyObject * args)
681
 
{
682
 
  float value;
683
 
 
684
 
  if (!PyArg_ParseTuple (args, "f", &value))
685
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
686
 
 
687
 
  self->camera->lens = EXPP_ClampFloat (value,
688
 
                                        EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
689
 
 
690
 
  Py_INCREF (Py_None);
691
 
  return Py_None;
692
 
}
693
 
 
694
 
static PyObject *
695
 
Camera_setClipStart (BPy_Camera * self, PyObject * args)
696
 
{
697
 
  float value;
698
 
 
699
 
  if (!PyArg_ParseTuple (args, "f", &value))
700
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
701
 
 
702
 
  self->camera->clipsta = EXPP_ClampFloat (value,
703
 
                                           EXPP_CAM_CLIPSTART_MIN,
704
 
                                           EXPP_CAM_CLIPSTART_MAX);
705
 
 
706
 
  Py_INCREF (Py_None);
707
 
  return Py_None;
708
 
}
709
 
 
710
 
static PyObject *
711
 
Camera_setClipEnd (BPy_Camera * self, PyObject * args)
712
 
{
713
 
  float value;
714
 
 
715
 
  if (!PyArg_ParseTuple (args, "f", &value))
716
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
717
 
 
718
 
  self->camera->clipend = EXPP_ClampFloat (value,
719
 
                                           EXPP_CAM_CLIPEND_MIN,
720
 
                                           EXPP_CAM_CLIPEND_MAX);
721
 
 
722
 
  Py_INCREF (Py_None);
723
 
  return Py_None;
724
 
}
725
 
 
726
 
static PyObject *
727
 
Camera_setDrawSize (BPy_Camera * self, PyObject * args)
728
 
{
729
 
  float value;
730
 
 
731
 
  if (!PyArg_ParseTuple (args, "f", &value))
732
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
733
 
                                  "expected a float number as argument");
734
 
 
735
 
  self->camera->drawsize = EXPP_ClampFloat (value,
736
 
                                            EXPP_CAM_DRAWSIZE_MIN,
737
 
                                            EXPP_CAM_DRAWSIZE_MAX);
738
 
 
739
 
  Py_INCREF (Py_None);
740
 
  return Py_None;
741
 
}
742
 
 
743
 
static void
744
 
Camera_dealloc (BPy_Camera * self)
745
 
{
746
 
  PyObject_DEL (self);
747
 
}
748
 
 
749
 
static PyObject *
750
 
Camera_getAttr (BPy_Camera * self, char *name)
751
 
{
752
 
  PyObject *attr = Py_None;
753
 
 
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)
769
 
    {
770
 
      Ipo *ipo = self->camera->ipo;
771
 
      if (ipo)
772
 
        attr = Ipo_CreatePyObject (ipo);
773
 
    }
774
 
 
775
 
  else if (strcmp (name, "Types") == 0)
776
 
    {
777
 
      attr = Py_BuildValue ("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP,
778
 
                            "ortho", EXPP_CAM_TYPE_ORTHO);
779
 
    }
780
 
 
781
 
  else if (strcmp (name, "Modes") == 0)
782
 
    {
783
 
      attr =
784
 
        Py_BuildValue ("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS,
785
 
                       "showMist", EXPP_CAM_MODE_SHOWMIST);
786
 
    }
787
 
 
788
 
  else if (strcmp (name, "__members__") == 0)
789
 
    {
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");
793
 
    }
794
 
 
795
 
  if (!attr)
796
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
797
 
                                  "couldn't create PyObject");
798
 
 
799
 
  if (attr != Py_None)
800
 
    return attr;                /* member attribute found, return it */
801
 
 
802
 
  /* not an attribute, search the methods table */
803
 
  return Py_FindMethod (BPy_Camera_methods, (PyObject *) self, name);
804
 
}
805
 
 
806
 
static int
807
 
Camera_setAttr (BPy_Camera * self, char *name, PyObject * value)
808
 
{
809
 
  PyObject *valtuple;
810
 
  PyObject *error = NULL;
 
682
static PyObject *Camera_setIntMode( BPy_Camera * self, PyObject * args )
 
683
{
 
684
        short value;
 
685
 
 
686
        if( !PyArg_ParseTuple( args, "h", &value ) )
 
687
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
688
                                              "expected int argument in [0,3]" );
 
689
 
 
690
        if( value >= 0 && value <= 3 )
 
691
                self->camera->flag = value;
 
692
        else
 
693
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
694
                                              "expected int argument in [0,3]" );
 
695
 
 
696
        Py_INCREF( Py_None );
 
697
        return Py_None;
 
698
}
 
699
 
 
700
static PyObject *Camera_setLens( BPy_Camera * self, PyObject * args )
 
701
{
 
702
        float value;
 
703
 
 
704
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
705
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
706
                                              "expected float argument" );
 
707
 
 
708
        self->camera->lens = EXPP_ClampFloat( value,
 
709
                                              EXPP_CAM_LENS_MIN,
 
710
                                              EXPP_CAM_LENS_MAX );
 
711
 
 
712
        Py_INCREF( Py_None );
 
713
        return Py_None;
 
714
}
 
715
 
 
716
static PyObject *Camera_setScale( BPy_Camera * self, PyObject * args )
 
717
{
 
718
        float value;
 
719
 
 
720
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
721
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
722
                                              "expected float argument" );
 
723
 
 
724
        self->camera->ortho_scale = EXPP_ClampFloat( value,
 
725
                                              EXPP_CAM_SCALE_MIN,
 
726
                                              EXPP_CAM_SCALE_MAX );
 
727
 
 
728
        Py_INCREF( Py_None );
 
729
        return Py_None;
 
730
}
 
731
 
 
732
static PyObject *Camera_setClipStart( BPy_Camera * self, PyObject * args )
 
733
{
 
734
        float value;
 
735
 
 
736
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
737
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
738
                                              "expected float argument" );
 
739
 
 
740
        self->camera->clipsta = EXPP_ClampFloat( value,
 
741
                                                 EXPP_CAM_CLIPSTART_MIN,
 
742
                                                 EXPP_CAM_CLIPSTART_MAX );
 
743
 
 
744
        Py_INCREF( Py_None );
 
745
        return Py_None;
 
746
}
 
747
 
 
748
static PyObject *Camera_setClipEnd( BPy_Camera * self, PyObject * args )
 
749
{
 
750
        float value;
 
751
 
 
752
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
753
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
754
                                              "expected float argument" );
 
755
 
 
756
        self->camera->clipend = EXPP_ClampFloat( value,
 
757
                                                 EXPP_CAM_CLIPEND_MIN,
 
758
                                                 EXPP_CAM_CLIPEND_MAX );
 
759
 
 
760
        Py_INCREF( Py_None );
 
761
        return Py_None;
 
762
}
 
763
 
 
764
static PyObject *Camera_setDrawSize( BPy_Camera * self, PyObject * args )
 
765
{
 
766
        float value;
 
767
 
 
768
        if( !PyArg_ParseTuple( args, "f", &value ) )
 
769
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
770
                                              "expected a float number as argument" );
 
771
 
 
772
        self->camera->drawsize = EXPP_ClampFloat( value,
 
773
                                                  EXPP_CAM_DRAWSIZE_MIN,
 
774
                                                  EXPP_CAM_DRAWSIZE_MAX );
 
775
 
 
776
        Py_INCREF( Py_None );
 
777
        return Py_None;
 
778
}
 
779
 
 
780
/* cam.addScriptLink */
 
781
static PyObject *Camera_addScriptLink( BPy_Camera * self, PyObject * args )
 
782
{
 
783
        Camera *cam = self->camera;
 
784
        ScriptLink *slink = NULL;
 
785
 
 
786
        slink = &( cam )->scriptlink;
 
787
 
 
788
        return EXPP_addScriptLink( slink, args, 0 );
 
789
}
 
790
 
 
791
/* cam.clearScriptLinks */
 
792
static PyObject *Camera_clearScriptLinks( BPy_Camera * self, PyObject * args )
 
793
{
 
794
        Camera *cam = self->camera;
 
795
        ScriptLink *slink = NULL;
 
796
 
 
797
        slink = &( cam )->scriptlink;
 
798
 
 
799
        return EXPP_clearScriptLinks( slink, args );
 
800
}
 
801
 
 
802
/* cam.getScriptLinks */
 
803
static PyObject *Camera_getScriptLinks( BPy_Camera * self, PyObject * args )
 
804
{
 
805
        Camera *cam = self->camera;
 
806
        ScriptLink *slink = NULL;
 
807
        PyObject *ret = NULL;
 
808
 
 
809
        slink = &( cam )->scriptlink;
 
810
 
 
811
        ret = EXPP_getScriptLinks( slink, args, 0 );
 
812
 
 
813
        if( ret )
 
814
                return ret;
 
815
        else
 
816
                return NULL;
 
817
}
 
818
 
 
819
static void Camera_dealloc( BPy_Camera * self )
 
820
{
 
821
        PyObject_DEL( self );
 
822
}
 
823
 
 
824
static PyObject *Camera_getAttr( BPy_Camera * self, char *name )
 
825
{
 
826
        PyObject *attr = Py_None;
 
827
 
 
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;
 
848
                if( ipo )
 
849
                        attr = Ipo_CreatePyObject( ipo );
 
850
        }
 
851
 
 
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 );
 
856
        }
 
857
 
 
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 );
 
862
        }
 
863
 
 
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" );
 
869
        }
 
870
 
 
871
        if( !attr )
 
872
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
873
                                              "couldn't create PyObject" );
 
874
 
 
875
        if( attr != Py_None )
 
876
                return attr;    /* member attribute found, return it */
 
877
 
 
878
        /* not an attribute, search the methods table */
 
879
        return Py_FindMethod( BPy_Camera_methods, ( PyObject * ) self, name );
 
880
}
 
881
 
 
882
static int Camera_setAttr( BPy_Camera * self, char *name, PyObject * value )
 
883
{
 
884
        PyObject *valtuple;
 
885
        PyObject *error = NULL;
811
886
 
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
816
891
 
817
892
/* First we put "value" in a tuple, because we want to pass it to functions
818
893
 * that only accept PyTuples. */
819
 
  valtuple = Py_BuildValue ("(O)", value);
 
894
        valtuple = Py_BuildValue( "(O)", value );
820
895
 
821
 
  if (!valtuple)                /* everything OK with our PyObject? */
822
 
    return EXPP_ReturnIntError (PyExc_MemoryError,
823
 
                                "CameraSetAttr: couldn't create PyTuple");
 
896
        if( !valtuple )         /* everything OK with our PyObject? */
 
897
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
898
                                            "CameraSetAttr: couldn't create PyTuple" );
824
899
 
825
900
/* Now we just compare "name" with all possible BPy_Camera member variables */
826
 
  if (strcmp (name, "name") == 0)
827
 
    error = Camera_setName (self, valtuple);
828
 
  else if (strcmp (name, "type") == 0)
829
 
    error = Camera_setIntType (self, valtuple); /* special case */
830
 
  else if (strcmp (name, "mode") == 0)
831
 
    error = Camera_setIntMode (self, valtuple); /* special case */
832
 
  else if (strcmp (name, "lens") == 0)
833
 
    error = Camera_setLens (self, valtuple);
834
 
  else if (strcmp (name, "clipStart") == 0)
835
 
    error = Camera_setClipStart (self, valtuple);
836
 
  else if (strcmp (name, "clipEnd") == 0)
837
 
    error = Camera_setClipEnd (self, valtuple);
838
 
  else if (strcmp (name, "drawSize") == 0)
839
 
    error = Camera_setDrawSize (self, valtuple);
840
 
 
841
 
  else
842
 
    {                           /* Error */
843
 
      Py_DECREF (valtuple);
844
 
 
845
 
      if ((strcmp (name, "Types") == 0) ||      /* user tried to change a */
846
 
          (strcmp (name, "Modes") == 0))        /* constant dict type ... */
847
 
        return EXPP_ReturnIntError (PyExc_AttributeError,
848
 
                                    "constant dictionary -- cannot be changed");
849
 
 
850
 
      else                      /* ... or no member with the given name was found */
851
 
        return EXPP_ReturnIntError (PyExc_KeyError, "attribute not found");
852
 
    }
 
901
        if( strcmp( name, "name" ) == 0 )
 
902
                error = Camera_setName( self, valtuple );
 
903
        else if( strcmp( name, "type" ) == 0 )
 
904
                error = Camera_setIntType( self, valtuple );    /* special case */
 
905
        else if( strcmp( name, "mode" ) == 0 )
 
906
                error = Camera_setIntMode( self, valtuple );    /* special case */
 
907
        else if( strcmp( name, "lens" ) == 0 )
 
908
                error = Camera_setLens( self, valtuple );
 
909
        else if( strcmp( name, "scale" ) == 0 )
 
910
                error = Camera_setScale( self, valtuple );
 
911
        else if( strcmp( name, "clipStart" ) == 0 )
 
912
                error = Camera_setClipStart( self, valtuple );
 
913
        else if( strcmp( name, "clipEnd" ) == 0 )
 
914
                error = Camera_setClipEnd( self, valtuple );
 
915
        else if( strcmp( name, "drawSize" ) == 0 )
 
916
                error = Camera_setDrawSize( self, valtuple );
 
917
 
 
918
        else {                  /* Error */
 
919
                Py_DECREF( valtuple );
 
920
 
 
921
                if( ( strcmp( name, "Types" ) == 0 ) || /* user tried to change a */
 
922
                    ( strcmp( name, "Modes" ) == 0 ) )  /* constant dict type ... */
 
923
                        return EXPP_ReturnIntError( PyExc_AttributeError,
 
924
                                                    "constant dictionary -- cannot be changed" );
 
925
 
 
926
                else            /* ... or no member with the given name was found */
 
927
                        return EXPP_ReturnIntError( PyExc_KeyError,
 
928
                                                    "attribute not found" );
 
929
        }
853
930
 
854
931
/* valtuple won't be returned to the caller, so we need to DECREF it */
855
 
  Py_DECREF (valtuple);
 
932
        Py_DECREF( valtuple );
856
933
 
857
 
  if (error != Py_None)
858
 
    return -1;
 
934
        if( error != Py_None )
 
935
                return -1;
859
936
 
860
937
/* Py_None was incref'ed by the called Camera_set* function. We probably
861
938
 * don't need to decref Py_None (!), but since Python/C API manual tells us
862
939
 * to treat it like any other PyObject regarding ref counting ... */
863
 
  Py_DECREF (Py_None);
864
 
  return 0;                     /* normal exit */
865
 
}
866
 
 
867
 
static int
868
 
Camera_compare (BPy_Camera * a, BPy_Camera * b)
869
 
{
870
 
  Camera *pa = a->camera, *pb = b->camera;
871
 
  return (pa == pb) ? 0 : -1;
872
 
}
873
 
 
874
 
static PyObject *
875
 
Camera_repr (BPy_Camera * self)
876
 
{
877
 
  return PyString_FromFormat ("[Camera \"%s\"]", self->camera->id.name + 2);
 
940
        Py_DECREF( Py_None );
 
941
        return 0;               /* normal exit */
 
942
}
 
943
 
 
944
static int Camera_compare( BPy_Camera * a, BPy_Camera * b )
 
945
{
 
946
        Camera *pa = a->camera, *pb = b->camera;
 
947
        return ( pa == pb ) ? 0 : -1;
 
948
}
 
949
 
 
950
static PyObject *Camera_repr( BPy_Camera * self )
 
951
{
 
952
        return PyString_FromFormat( "[Camera \"%s\"]",
 
953
                                    self->camera->id.name + 2 );
 
954
}
 
955
 
 
956
/*
 
957
 * Camera_insertIpoKey()
 
958
 *  inserts Camera IPO key for LENS and CLIPPING
 
959
 */
 
960
 
 
961
static PyObject *Camera_insertIpoKey( BPy_Camera * self, PyObject * args )
 
962
{
 
963
        int key = 0;
 
964
 
 
965
        if( !PyArg_ParseTuple( args, "i", &( key ) ) )
 
966
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
967
                                                                                "expected int argument" ) );
 
968
 
 
969
        if (key == IPOKEY_LENS){
 
970
                insertkey((ID *)self->camera, CAM_LENS);     
 
971
        }
 
972
        else if (key == IPOKEY_CLIPPING){
 
973
                insertkey((ID *)self->camera, CAM_STA);
 
974
                insertkey((ID *)self->camera, CAM_END);   
 
975
        }
 
976
 
 
977
        allspace(REMAKEIPO, 0);
 
978
        EXPP_allqueue(REDRAWIPO, 0);
 
979
        EXPP_allqueue(REDRAWVIEW3D, 0);
 
980
        EXPP_allqueue(REDRAWACTION, 0);
 
981
        EXPP_allqueue(REDRAWNLA, 0);
 
982
 
 
983
        return EXPP_incr_ret( Py_None );
878
984
}