Merge from trunk
[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 "PyObjectPlus.h"
31 #include "KX_ConstraintWrapper.h"
32 #include "PHY_IPhysicsEnvironment.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 KX_ConstraintWrapper::KX_ConstraintWrapper(
39                                                 PHY_ConstraintType ctype,
40                                                 int constraintId,
41                                                 PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) :
42                 PyObjectPlus(T),
43                 m_constraintId(constraintId),
44                 m_constraintType(ctype),
45                 m_physenv(physenv)
46 {
47 }
48 KX_ConstraintWrapper::~KX_ConstraintWrapper()
49 {
50 }
51 //python integration methods
52 PyObject* KX_ConstraintWrapper::PyTestMethod(PyObject* self, 
53                                                                                         PyObject* args, 
54                                                                                         PyObject* kwds)
55 {
56         
57         Py_RETURN_NONE;
58 }
59
60 PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self, 
61                                                                                         PyObject* args, 
62                                                                                         PyObject* kwds)
63 {
64         return PyInt_FromLong(m_constraintId);
65 }
66
67
68
69
70 //python specific stuff
71 PyTypeObject KX_ConstraintWrapper::Type = {
72         PyObject_HEAD_INIT(&PyType_Type)
73                 0,
74                 "KX_ConstraintWrapper",
75                 sizeof(KX_ConstraintWrapper),
76                 0,
77                 PyDestructor,
78                 0,
79                 __getattr,
80                 __setattr,
81                 0, //&MyPyCompare,
82                 __repr,
83                 0, //&cvalue_as_number,
84                 0,
85                 0,
86                 0,
87                 0
88 };
89
90 PyParentObject KX_ConstraintWrapper::Parents[] = {
91         &KX_ConstraintWrapper::Type,
92         NULL
93 };
94
95 PyObject*       KX_ConstraintWrapper::_getattr(const STR_String& attr)
96 {
97         //here you can search for existing data members (like mass,friction etc.)
98         _getattr_up(PyObjectPlus);
99 }
100
101 int     KX_ConstraintWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
102 {
103         
104         PyTypeObject* type = pyobj->ob_type;
105         int result = 1;
106
107         if (type == &PyList_Type)
108         {
109                 result = 0;
110         }
111         if (type == &PyFloat_Type)
112         {
113                 result = 0;
114
115         }
116         if (type == &PyInt_Type)
117         {
118                 result = 0;
119         }
120         if (type == &PyString_Type)
121         {
122                 result = 0;
123         }
124         if (result)
125                 result = PyObjectPlus::_setattr(attr,pyobj);
126         return result;
127 };
128
129
130 PyMethodDef KX_ConstraintWrapper::Methods[] = {
131         {"testMethod",(PyCFunction) KX_ConstraintWrapper::sPyTestMethod, METH_VARARGS},
132         {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
133         {NULL,NULL} //Sentinel
134 };