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