game engine python api
[blender.git] / source / gameengine / Ketsji / KX_ConstraintWrapper.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29 #include <Python.h>
30 #include "KX_ConstraintWrapper.h"
31 #include "PHY_IPhysicsEnvironment.h"
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36
37 KX_ConstraintWrapper::KX_ConstraintWrapper(
38                                                 PHY_ConstraintType ctype,
39                                                 int constraintId,
40                                                 PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
41                 PyObjectPlus(T),
42                 m_constraintId(constraintId),
43                 m_constraintType(ctype),
44                 m_physenv(physenv)
45 {
46 }
47 KX_ConstraintWrapper::~KX_ConstraintWrapper()
48 {
49 }
50 //python integration methods
51 PyObject* KX_ConstraintWrapper::PyTestMethod(PyObject* self, 
52                                                                                         PyObject* args, 
53                                                                                         PyObject* kwds)
54 {
55         
56         Py_RETURN_NONE;
57 }
58
59 PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self, 
60                                                                                         PyObject* args, 
61                                                                                         PyObject* kwds)
62 {
63         return PyInt_FromLong(m_constraintId);
64 }
65
66
67
68
69 //python specific stuff
70 PyTypeObject KX_ConstraintWrapper::Type = {
71         PyObject_HEAD_INIT(&PyType_Type)
72                 0,
73                 "KX_ConstraintWrapper",
74                 sizeof(KX_ConstraintWrapper),
75                 0,
76                 PyDestructor,
77                 0,
78                 __getattr,
79                 __setattr,
80                 0, //&MyPyCompare,
81                 __repr,
82                 0, //&cvalue_as_number,
83                 0,
84                 0,
85                 0,
86                 0
87 };
88
89 PyParentObject KX_ConstraintWrapper::Parents[] = {
90         &KX_ConstraintWrapper::Type,
91         NULL
92 };
93
94 PyObject*       KX_ConstraintWrapper::_getattr(const STR_String& attr)
95 {
96         //here you can search for existing data members (like mass,friction etc.)
97         _getattr_up(PyObjectPlus);
98 }
99
100 int     KX_ConstraintWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
101 {
102         
103         PyTypeObject* type = pyobj->ob_type;
104         int result = 1;
105
106         if (type == &PyList_Type)
107         {
108                 result = 0;
109         }
110         if (type == &PyFloat_Type)
111         {
112                 result = 0;
113
114         }
115         if (type == &PyInt_Type)
116         {
117                 result = 0;
118         }
119         if (type == &PyString_Type)
120         {
121                 result = 0;
122         }
123         if (result)
124                 result = PyObjectPlus::_setattr(attr,pyobj);
125         return result;
126 };
127
128
129 PyMethodDef KX_ConstraintWrapper::Methods[] = {
130         {"testMethod",(PyCFunction) KX_ConstraintWrapper::sPyTestMethod, METH_VARARGS},
131         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
132         {NULL,NULL} //Sentinel
133 };