soc-2008-mxcurioni: moved namespace collision resolution to the freestyle_init.py...
[blender.git] / source / blender / freestyle / intern / python / Interface1D / FEdge / BPy_FEdgeSharp.cpp
1 #include "BPy_FEdgeSharp.h"
2
3 #include "../../BPy_Convert.h"
4 #include "../../Interface0D/BPy_SVertex.h"
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 ///////////////////////////////////////////////////////////////////////////////////////////
11
12 /*---------------  Python API function prototypes for FEdgeSharp instance  -----------*/
13 static int FEdgeSharp___init__(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds);
14
15 static PyObject * FEdgeSharp_normalA( BPy_FEdgeSharp *self ) ;
16 static PyObject * FEdgeSharp_normalB( BPy_FEdgeSharp *self );
17 static PyObject * FEdgeSharp_aMaterialIndex( BPy_FEdgeSharp *self ) ;
18 static PyObject * FEdgeSharp_bMaterialIndex( BPy_FEdgeSharp *self );
19 static PyObject * FEdgeSharp_aMaterial( BPy_FEdgeSharp *self );
20 static PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self );
21 static PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args );
22 static PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args );
23 static PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args );
24 static PyObject * FEdgeSharp_setbMaterialIndex( BPy_FEdgeSharp *self, PyObject *args );
25
26 /*----------------------FEdgeSharp instance definitions ----------------------------*/
27 static PyMethodDef BPy_FEdgeSharp_methods[] = { 
28         {"normalA", ( PyCFunction ) FEdgeSharp_normalA, METH_NOARGS, "() Returns the normal to the face lying on the right of the FEdge. If this FEdge is a border, it has no Face on its right and therefore, no normal."},
29         {"normalB", ( PyCFunction ) FEdgeSharp_normalB, METH_NOARGS, "() Returns the normal to the face lying on the left of the FEdge."},
30         {"aMaterialIndex", ( PyCFunction ) FEdgeSharp_aMaterialIndex, METH_NOARGS, "() Returns the index of the material of the face lying on the right of the FEdge. If this FEdge is a border, it has no Face on its right and therefore, no material. "},
31         {"bMaterialIndex", ( PyCFunction ) FEdgeSharp_bMaterialIndex, METH_NOARGS, "() Returns the material of the face lying on the left of the FEdge. "},
32         {"aMaterial", ( PyCFunction ) FEdgeSharp_aMaterial, METH_NOARGS, "() Returns the material of the face lying on the right of the FEdge. If this FEdge is a border, it has no Face on its right and therefore, no material."},
33         {"bMaterial", ( PyCFunction ) FEdgeSharp_bMaterial, METH_NOARGS, "() Returns the material of the face lying on the left of the FEdge."},
34         {"setNormalA", ( PyCFunction ) FEdgeSharp_setNormalA, METH_VARARGS, "([x,y,z]) Sets the normal to the face lying on the right of the FEdge."},
35         {"setNormalB", ( PyCFunction ) FEdgeSharp_setNormalB, METH_VARARGS, "([x,y,z]) Sets the normal to the face lying on the left of the FEdge. "},
36         {"setaMaterialIndex", ( PyCFunction ) FEdgeSharp_setaMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material lying on the right of the FEdge. "},
37         {"setbMaterialIndex", ( PyCFunction ) FEdgeSharp_setbMaterialIndex, METH_VARARGS, "(unsigned int i) Sets the index of the material lying on the left of the FEdge. "},
38         {NULL, NULL, 0, NULL}
39 };
40
41 /*-----------------------BPy_FEdgeSharp type definition ------------------------------*/
42
43 PyTypeObject FEdgeSharp_Type = {
44         PyObject_HEAD_INIT( NULL ) 
45         0,                                                      /* ob_size */
46         "FEdgeSharp",                           /* tp_name */
47         sizeof( BPy_FEdgeSharp ),       /* tp_basicsize */
48         0,                                                      /* tp_itemsize */
49         
50         /* methods */
51         NULL,   /* tp_dealloc */
52         NULL,                                                   /* printfunc tp_print; */
53         NULL,                                                   /* getattrfunc tp_getattr; */
54         NULL,                                                   /* setattrfunc tp_setattr; */
55         NULL,                                                                           /* tp_compare */
56         NULL,                                   /* tp_repr */
57
58         /* Method suites for standard classes */
59
60         NULL,                       /* PyNumberMethods *tp_as_number; */
61         NULL,                       /* PySequenceMethods *tp_as_sequence; */
62         NULL,                       /* PyMappingMethods *tp_as_mapping; */
63
64         /* More standard operations (here for binary compatibility) */
65
66         NULL,                                           /* hashfunc tp_hash; */
67         NULL,                       /* ternaryfunc tp_call; */
68         NULL,                       /* reprfunc tp_str; */
69         NULL,                       /* getattrofunc tp_getattro; */
70         NULL,                       /* setattrofunc tp_setattro; */
71
72         /* Functions to access object as input/output buffer */
73         NULL,                       /* PyBufferProcs *tp_as_buffer; */
74
75   /*** Flags to define presence of optional/expanded features ***/
76         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* long tp_flags; */
77
78         NULL,                       /*  char *tp_doc;  Documentation string */
79   /*** Assigned meaning in release 2.0 ***/
80         /* call function for all accessible objects */
81         NULL,                       /* traverseproc tp_traverse; */
82
83         /* delete references to contained objects */
84         NULL,                       /* inquiry tp_clear; */
85
86   /***  Assigned meaning in release 2.1 ***/
87   /*** rich comparisons ***/
88         NULL,                       /* richcmpfunc tp_richcompare; */
89
90   /***  weak reference enabler ***/
91         0,                          /* long tp_weaklistoffset; */
92
93   /*** Added in release 2.2 ***/
94         /*   Iterators */
95         NULL,                       /* getiterfunc tp_iter; */
96         NULL,                       /* iternextfunc tp_iternext; */
97
98   /*** Attribute descriptor and subclassing stuff ***/
99         BPy_FEdgeSharp_methods, /* struct PyMethodDef *tp_methods; */
100         NULL,                           /* struct PyMemberDef *tp_members; */
101         NULL,                                           /* struct PyGetSetDef *tp_getset; */
102         &FEdge_Type,                            /* struct _typeobject *tp_base; */
103         NULL,                                                   /* PyObject *tp_dict; */
104         NULL,                                                   /* descrgetfunc tp_descr_get; */
105         NULL,                                                   /* descrsetfunc tp_descr_set; */
106         0,                              /* long tp_dictoffset; */
107         (initproc)FEdgeSharp___init__,                          /* initproc tp_init; */
108         NULL,                                                   /* allocfunc tp_alloc; */
109         NULL,           /* newfunc tp_new; */
110         
111         /*  Low-level free-memory routine */
112         NULL,                       /* freefunc tp_free;  */
113         
114         /* For PyObject_IS_GC */
115         NULL,                       /* inquiry tp_is_gc;  */
116         NULL,                       /* PyObject *tp_bases; */
117         
118         /* method resolution order */
119         NULL,                       /* PyObject *tp_mro;  */
120         NULL,                       /* PyObject *tp_cache; */
121         NULL,                       /* PyObject *tp_subclasses; */
122         NULL,                       /* PyObject *tp_weaklist; */
123         NULL
124 };
125
126 //------------------------INSTANCE METHODS ----------------------------------
127
128 int FEdgeSharp___init__(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
129 {
130         PyObject *obj1 = 0, *obj2 = 0;
131
132     if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) )
133         return -1;
134
135         if( !obj1 ){
136                 self->fes = new FEdgeSharp();
137                 
138         } else if( BPy_FEdgeSharp_Check(obj1) ) {
139                 if( ((BPy_FEdgeSharp *) obj1)->fes )
140                         self->fes = new FEdgeSharp(*( ((BPy_FEdgeSharp *) obj1)->fes ));
141                 else
142                         return -1;
143                 
144         } else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) {
145                 self->fes = new FEdgeSharp( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv );
146
147         } else {
148                 return -1;
149         }
150
151         self->py_fe.fe = self->fes;
152         self->py_fe.py_if1D.if1D = self->fes;
153
154         return 0;
155 }
156
157
158 PyObject * FEdgeSharp_normalA( BPy_FEdgeSharp *self ) {
159         Vec3r v( self->fes->normalA() );
160         return Vector_from_Vec3r( v );
161 }
162
163 PyObject * FEdgeSharp_normalB( BPy_FEdgeSharp *self ) {
164         Vec3r v( self->fes->normalB() );
165         return Vector_from_Vec3r( v );
166 }
167
168 PyObject * FEdgeSharp_aMaterialIndex( BPy_FEdgeSharp *self ) {
169         return PyInt_FromLong( self->fes->aMaterialIndex() );
170 }
171
172 PyObject * FEdgeSharp_bMaterialIndex( BPy_FEdgeSharp *self ) {
173         return PyInt_FromLong( self->fes->bMaterialIndex() );
174 }
175
176 PyObject * FEdgeSharp_aMaterial( BPy_FEdgeSharp *self ) {
177         Material m( self->fes->aMaterial() );
178         return BPy_Material_from_Material(m);
179 }
180
181 PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) {
182         Material m( self->fes->aMaterial() );
183         return BPy_Material_from_Material(m);
184 }
185
186 PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) {
187         PyObject *obj = 0;
188
189         if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) {
190                 cout << "ERROR: FEdgeSharp_setNormalA" << endl;
191                 Py_RETURN_NONE;
192         }
193         
194         Vec3r v(        PyFloat_AsDouble( PyList_GetItem(obj,0) ),
195                                 PyFloat_AsDouble( PyList_GetItem(obj,1) ),
196                                 PyFloat_AsDouble( PyList_GetItem(obj,2) ) );
197
198         self->fes->setNormalA( v );
199
200         Py_RETURN_NONE;
201 }
202
203 PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) {
204         PyObject *obj = 0;
205
206         if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) {
207                 cout << "ERROR: FEdgeSharp_setNormalB" << endl;
208                 Py_RETURN_NONE;
209         }
210         
211         Vec3r v(        PyFloat_AsDouble( PyList_GetItem(obj,0) ),
212                                 PyFloat_AsDouble( PyList_GetItem(obj,1) ),
213                                 PyFloat_AsDouble( PyList_GetItem(obj,2) ) );
214
215         self->fes->setNormalB( v );
216
217         Py_RETURN_NONE;
218 }
219
220 PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) {
221         unsigned int i;
222
223         if(!( PyArg_ParseTuple(args, "I", &i) )) {
224                 cout << "ERROR: FEdgeSharp_setaMaterialIndex" << endl;
225                 Py_RETURN_NONE;
226         }
227         
228         self->fes->setaMaterialIndex( i );
229
230         Py_RETURN_NONE;
231 }
232
233 PyObject * FEdgeSharp_setbMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) {
234         unsigned int i;
235
236         if(!( PyArg_ParseTuple(args, "I", &i) )) {
237                 cout << "ERROR: FEdgeSharp_setbMaterialIndex" << endl;
238                 Py_RETURN_NONE;
239         }
240         
241         self->fes->setbMaterialIndex( i );
242
243         Py_RETURN_NONE;
244 }
245
246 ///////////////////////////////////////////////////////////////////////////////////////////
247
248 #ifdef __cplusplus
249 }
250 #endif