| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Willian P. Germano | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | #include <BKE_main.h>
 | 
					
						
							|  |  |  | #include <BKE_global.h>
 | 
					
						
							|  |  |  | #include <BKE_object.h>
 | 
					
						
							|  |  |  | #include <BKE_library.h>
 | 
					
						
							|  |  |  | #include <BLI_blenlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | #include "Camera.h"
 | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python Camera_Type structure definition:                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyTypeObject Camera_Type = | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject_HEAD_INIT(NULL) | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  |   0,                             /* ob_size */ | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  |   "Blender Camera",              /* tp_name */ | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  |   sizeof (BPy_Camera),           /* tp_basicsize */ | 
					
						
							|  |  |  |   0,                             /* tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  |   /* methods */ | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  |   (destructor)Camera_dealloc,    /* tp_dealloc */ | 
					
						
							| 
									
										
										
										
											2003-07-04 02:56:07 +00:00
										 |  |  |   0,                             /* tp_print */ | 
					
						
							|  |  |  | 	(getattrfunc)Camera_getAttr,   /* tp_getattr */ | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  |   (setattrfunc)Camera_setAttr,   /* tp_setattr */ | 
					
						
							|  |  |  |   (cmpfunc)Camera_compare,       /* tp_compare */ | 
					
						
							|  |  |  |   (reprfunc)Camera_repr,         /* tp_repr */ | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  |   0,                             /* tp_as_number */ | 
					
						
							|  |  |  |   0,                             /* tp_as_sequence */ | 
					
						
							|  |  |  |   0,                             /* tp_as_mapping */ | 
					
						
							|  |  |  |   0,                             /* tp_as_hash */ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  |   0,0,0,0,0,0, | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  |   0,                             /* tp_doc */  | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  |   0,0,0,0,0,0, | 
					
						
							| 
									
										
										
										
											2003-06-13 04:21:48 +00:00
										 |  |  |   BPy_Camera_methods,            /* tp_methods */ | 
					
						
							|  |  |  |   0,                             /* tp_members */ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   char        *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */ | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   char        *name_str = "CamData"; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   static char *kwlist[] = {"type_str", "name_str", NULL}; | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   PyObject    *pycam; /* for Camera Data object wrapper in Python */ | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   Camera      *blcam; /* for actual Camera Data we create in Blender */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   char        buf[21]; | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  |   /* Parse the arguments passed in by the Python interpreter */ | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  |   if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist, | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |                                    &type_str, &name_str)) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   /* We expected string(s) (or nothing) as argument, but we didn't get that. */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |             "expected zero, one or two strings as arguments"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   blcam = add_camera(); /* first create the Camera Data in Blender */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (blcam) /* now create the wrapper obj in Python */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     pycam = Camera_CreatePyObject (blcam); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                             "couldn't create Camera Data in Blender"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  |   /* let's return user count to zero, because ... */ | 
					
						
							|  |  |  |   blcam->id.us = 0; /* ... add_camera() incref'ed it */ | 
					
						
							|  |  |  |   /* XXX XXX Do this in other modules, too */ | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (pycam == NULL) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  |                             "couldn't create Camera PyObject"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */ | 
					
						
							|  |  |  |     /*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */ | 
					
						
							|  |  |  |   else if (strcmp (type_str, "ortho") == 0) | 
					
						
							|  |  |  |     blcam->type = (short)EXPP_CAM_TYPE_ORTHO; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |             "unknown camera type"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   if (strcmp (name_str, "CamData") == 0) | 
					
						
							|  |  |  |     return pycam; | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   else { /* user gave us a name for the camera, use it */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     PyOS_snprintf (buf, sizeof(buf), "%s", name_str); | 
					
						
							|  |  |  |     rename_id (&blcam->id, buf); /* proper way in Blender */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return pycam; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | static PyObject *M_Camera_Get(PyObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |   char   *name = NULL; | 
					
						
							|  |  |  |   Camera *cam_iter; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "|s", &name)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |             "expected string argument (or nothing)"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   cam_iter = G.main->camera.first; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   if (name) { /* (name) - Search camera by name */ | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     PyObject *wanted_cam = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (cam_iter && !wanted_cam) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  |       if (strcmp (name, cam_iter->id.name+2) == 0) { | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         wanted_cam = Camera_CreatePyObject (cam_iter); | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |       cam_iter = cam_iter->id.next; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     if (!wanted_cam) { /* Requested camera doesn't exist */ | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |       char error_msg[64]; | 
					
						
							|  |  |  |       PyOS_snprintf(error_msg, sizeof(error_msg), | 
					
						
							|  |  |  |                       "Camera \"%s\" not found", name); | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       return EXPP_ReturnPyObjError (PyExc_NameError, error_msg); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return wanted_cam; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   else { /* () - return a list of wrappers for all cameras in the scene */ | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     int index = 0; | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     PyObject *cam_pylist, *pyobj; | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     cam_pylist = PyList_New (BLI_countlist (&(G.main->camera))); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     if (!cam_pylist) | 
					
						
							|  |  |  |       return PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  |               "couldn't create PyList"); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |     while (cam_iter) { | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       pyobj = Camera_CreatePyObject (cam_iter); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       if (!pyobj) | 
					
						
							|  |  |  |         return PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  |                   "couldn't create Camera PyObject"); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       PyList_SET_ITEM (cam_pylist, index, pyobj); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |       cam_iter = cam_iter->id.next; | 
					
						
							|  |  |  |       index++; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return cam_pylist; | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-24 07:21:17 +00:00
										 |  |  | PyObject *Camera_Init (void) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject  *submodule; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-02 20:15:50 +00:00
										 |  |  |   Camera_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   submodule = Py_InitModule3("Blender.Camera", | 
					
						
							|  |  |  |                   M_Camera_methods, M_Camera_doc); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return submodule; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | /* Three Python Camera_Type helper functions needed by the Object module: */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | PyObject *Camera_CreatePyObject (Camera *cam) | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   BPy_Camera *pycam; | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   pycam = (BPy_Camera *)PyObject_NEW (BPy_Camera, &Camera_Type); | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   if (!pycam) | 
					
						
							|  |  |  |     return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |             "couldn't create BPy_Camera PyObject"); | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   pycam->camera = cam; | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   return (PyObject *)pycam; | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | int Camera_CheckPyObject (PyObject *pyobj) | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   return (pyobj->ob_type == &Camera_Type); | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | Camera *Camera_FromPyObject (PyObject *pyobj) | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   return ((BPy_Camera *)pyobj)->camera; | 
					
						
							| 
									
										
										
										
											2003-05-20 03:56:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | /* Python BPy_Camera methods:                                                */ | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getName(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyString_FromString(self->camera->id.name+2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.name attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getType(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *attr = PyInt_FromLong(self->camera->type); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.type attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getMode(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyInt_FromLong(self->camera->flag); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.Mode attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getLens(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyFloat_FromDouble(self->camera->lens); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.lens attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getClipStart(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyFloat_FromDouble(self->camera->clipsta); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.clipStart attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getClipEnd(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyFloat_FromDouble(self->camera->clipend); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.clipEnd attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_getDrawSize(BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyFloat_FromDouble(self->camera->drawsize); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   return EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |                                    "couldn't get Camera.drawSize attribute"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setName(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   char *name; | 
					
						
							|  |  |  |   char buf[21]; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "s", &name)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected string argument"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyOS_snprintf(buf, sizeof(buf), "%s", name); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   rename_id(&self->camera->id, buf); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setType(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   char *type; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "s", &type)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected string argument"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (strcmp (type, "persp") == 0) | 
					
						
							|  |  |  |     self->camera->type = (short)EXPP_CAM_TYPE_PERSP; | 
					
						
							|  |  |  |   else if (strcmp (type, "ortho") == 0) | 
					
						
							|  |  |  |     self->camera->type = (short)EXPP_CAM_TYPE_ORTHO;   | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |                                      "unknown camera type"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /* This one is 'private'. It is not really a method, just a helper function for
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  |  * when script writers use Camera.type = t instead of Camera.setType(t), since | 
					
						
							|  |  |  |  * in the first case t should be an int and in the second a string. So while | 
					
						
							|  |  |  |  * the method setType expects a string ('persp' or 'ortho') or an empty | 
					
						
							|  |  |  |  * argument, this function should receive an int (0 or 1). */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setIntType(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   short value; | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "h", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected int argument: 0 or 1"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   if (value == 0 || value == 1) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |     self->camera->type = value; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_ValueError, | 
					
						
							|  |  |  |                                      "expected int argument: 0 or 1"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   char *mode_str1 = NULL, *mode_str2 = NULL; | 
					
						
							|  |  |  |   short flag = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |             "expected one or two strings as arguments"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (mode_str1 != NULL) { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |     if (strcmp(mode_str1, "showLimits") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |       flag |= (short)EXPP_CAM_MODE_SHOWLIMITS; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |     else if (strcmp(mode_str1, "showMist") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |       flag |= (short)EXPP_CAM_MODE_SHOWMIST; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |                               "first argument is an unknown camera flag"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |     if (mode_str2 != NULL) { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |       if (strcmp(mode_str2, "showLimits") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |         flag |= (short)EXPP_CAM_MODE_SHOWLIMITS; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |       else if (strcmp(mode_str2, "showMist") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |         flag |= (short)EXPP_CAM_MODE_SHOWMIST; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         return EXPP_ReturnPyObjError (PyExc_AttributeError, | 
					
						
							|  |  |  |                               "second argument is an unknown camera flag"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   self->camera->flag = flag; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /* Another helper function, for the same reason.
 | 
					
						
							|  |  |  |  * (See comment before Camera_setIntType above). */ | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setIntMode(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   short value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "h", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected int argument in [0,3]"); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   if (value >= 0 && value <= 3) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |     self->camera->flag = value; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_ValueError, | 
					
						
							|  |  |  |                                      "expected int argument in [0,3]"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setLens(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float value; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "f", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected float argument"); | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   self->camera->lens = EXPP_ClampFloat (value, | 
					
						
							|  |  |  |                   EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setClipStart(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float value; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "f", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected float argument"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   self->camera->clipsta = EXPP_ClampFloat (value, | 
					
						
							|  |  |  |                   EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setClipEnd(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float value; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "f", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected float argument"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   self->camera->clipend = EXPP_ClampFloat (value, | 
					
						
							|  |  |  |                   EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | static PyObject *Camera_setDrawSize(BPy_Camera *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float value; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "f", &value)) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							|  |  |  |                                      "expected a float number as argument"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   self->camera->drawsize = EXPP_ClampFloat (value, | 
					
						
							|  |  |  |                   EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static void Camera_dealloc (BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   PyObject_DEL (self); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static PyObject *Camera_getAttr (BPy_Camera *self, char *name) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = Py_None; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (strcmp(name, "name") == 0) | 
					
						
							|  |  |  |     attr = PyString_FromString(self->camera->id.name+2); | 
					
						
							|  |  |  |   else if (strcmp(name, "type") == 0) | 
					
						
							|  |  |  |     attr = PyInt_FromLong(self->camera->type); | 
					
						
							|  |  |  |   else if (strcmp(name, "mode") == 0) | 
					
						
							|  |  |  |     attr = PyInt_FromLong(self->camera->flag); | 
					
						
							|  |  |  |   else if (strcmp(name, "lens") == 0) | 
					
						
							|  |  |  |     attr = PyFloat_FromDouble(self->camera->lens); | 
					
						
							|  |  |  |   else if (strcmp(name, "clipStart") == 0) | 
					
						
							|  |  |  |     attr = PyFloat_FromDouble(self->camera->clipsta); | 
					
						
							|  |  |  |   else if (strcmp(name, "clipEnd") == 0) | 
					
						
							|  |  |  |     attr = PyFloat_FromDouble(self->camera->clipend); | 
					
						
							|  |  |  |   else if (strcmp(name, "drawSize") == 0) | 
					
						
							|  |  |  |     attr = PyFloat_FromDouble(self->camera->drawsize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   else if (strcmp(name, "Types") == 0) { | 
					
						
							|  |  |  |     attr = Py_BuildValue("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP, | 
					
						
							|  |  |  |                                       "ortho", EXPP_CAM_TYPE_ORTHO); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   else if (strcmp(name, "Modes") == 0) { | 
					
						
							|  |  |  |     attr = Py_BuildValue("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS, | 
					
						
							|  |  |  |                                   "showMist", EXPP_CAM_MODE_SHOWMIST); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   else if (strcmp(name, "__members__") == 0) { | 
					
						
							|  |  |  |     attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s]", | 
					
						
							|  |  |  |                     "name", "type", "mode", "lens", "clipStart", | 
					
						
							|  |  |  |                     "clipEnd", "drawSize", "Types", "Modes"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!attr) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  |                       "couldn't create PyObject"); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (attr != Py_None) return attr; /* member attribute found, return it */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   /* not an attribute, search the methods table */ | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  |   return Py_FindMethod(BPy_Camera_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static int Camera_setAttr (BPy_Camera *self, char *name, PyObject *value) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   PyObject *valtuple;  | 
					
						
							|  |  |  |   PyObject *error = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* We're playing a trick on the Python API users here.  Even if they use
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |  * Camera.member = val instead of Camera.setMember(val), we end up using the | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |  * function anyway, since it already has error checking, clamps to the right | 
					
						
							|  |  |  |  * interval and updates the Blender Camera structure when necessary. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | /* First we put "value" in a tuple, because we want to pass it to functions
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  |  * that only accept PyTuples. */ | 
					
						
							|  |  |  |   valtuple = Py_BuildValue("(O)", value); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!valtuple) /* everything OK with our PyObject? */ | 
					
						
							|  |  |  |     return EXPP_ReturnIntError(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |                          "CameraSetAttr: couldn't create PyTuple"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 16:21:44 +00:00
										 |  |  | /* Now we just compare "name" with all possible BPy_Camera member variables */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   if (strcmp (name, "name") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  |     error = Camera_setName (self, valtuple); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   else if (strcmp (name, "type") == 0) | 
					
						
							|  |  |  |     error = Camera_setIntType (self, valtuple); /* special case */ | 
					
						
							|  |  |  |   else if (strcmp (name, "mode") == 0) | 
					
						
							|  |  |  |     error = Camera_setIntMode (self, valtuple); /* special case */ | 
					
						
							|  |  |  |   else if (strcmp (name, "lens") == 0) | 
					
						
							|  |  |  |     error = Camera_setLens (self, valtuple); | 
					
						
							|  |  |  |   else if (strcmp (name, "clipStart") == 0) | 
					
						
							|  |  |  |     error = Camera_setClipStart (self, valtuple); | 
					
						
							|  |  |  |   else if (strcmp (name, "clipEnd") == 0) | 
					
						
							|  |  |  |     error = Camera_setClipEnd (self, valtuple); | 
					
						
							|  |  |  |   else if (strcmp (name, "drawSize") == 0) | 
					
						
							|  |  |  |     error = Camera_setDrawSize (self, valtuple); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   else { /* Error */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |     Py_DECREF(valtuple); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |     if ((strcmp (name, "Types") == 0) || /* user tried to change a */ | 
					
						
							|  |  |  |         (strcmp (name, "Modes") == 0))   /* constant dict type ... */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       return EXPP_ReturnIntError (PyExc_AttributeError, | 
					
						
							|  |  |  |                    "constant dictionary -- cannot be changed"); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     else /* ... or no member with the given name was found */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       return EXPP_ReturnIntError (PyExc_KeyError, | 
					
						
							|  |  |  |                    "attribute not found"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | /* valtuple won't be returned to the caller, so we need to DECREF it */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   Py_DECREF (valtuple); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (error != Py_None) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Py_None was incref'ed by the called Camera_set* function. We probably
 | 
					
						
							|  |  |  |  * don't need to decref Py_None (!), but since Python/C API manual tells us | 
					
						
							|  |  |  |  * to treat it like any other PyObject regarding ref counting ... */ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   Py_DECREF (Py_None); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   return 0; /* normal exit */ | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static int Camera_compare (BPy_Camera *a, BPy_Camera *b) | 
					
						
							| 
									
										
										
										
											2003-05-21 19:58:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-07 03:49:45 +00:00
										 |  |  |   Camera *pa = a->camera, *pb = b->camera; | 
					
						
							|  |  |  |   return (pa == pb) ? 0:-1; | 
					
						
							| 
									
										
										
										
											2003-05-21 19:58:31 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-07-05 01:18:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | static PyObject *Camera_repr (BPy_Camera *self) | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-07-04 02:56:07 +00:00
										 |  |  |   return PyString_FromFormat("[Camera \"%s\"]", self->camera->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-03-25 19:16:13 +00:00
										 |  |  | } |