Merged changes in the trunk up to revision 36301.
[blender.git] / source / blender / freestyle / intern / python / BPy_Convert.cpp
1 #include "BPy_Convert.h"
2
3 #include "BPy_BBox.h"
4 #include "BPy_FrsMaterial.h"
5 #include "BPy_Id.h"
6 #include "BPy_IntegrationType.h"
7 #include "BPy_Interface0D.h"
8 #include "Interface0D/BPy_CurvePoint.h"
9 #include "Interface0D/CurvePoint/BPy_StrokeVertex.h"
10 #include "Interface0D/BPy_SVertex.h"
11 #include "Interface0D/BPy_ViewVertex.h"
12 #include "Interface0D/ViewVertex/BPy_NonTVertex.h"
13 #include "Interface0D/ViewVertex/BPy_TVertex.h"
14 #include "BPy_Interface1D.h"
15 #include "Interface1D/BPy_FEdge.h"
16 #include "Interface1D/BPy_Stroke.h"
17 #include "Interface1D/BPy_ViewEdge.h"
18 #include "Interface1D/Curve/BPy_Chain.h"
19 #include "Interface1D/FEdge/BPy_FEdgeSharp.h"
20 #include "Interface1D/FEdge/BPy_FEdgeSmooth.h"
21 #include "BPy_Nature.h"
22 #include "BPy_MediumType.h"
23 #include "BPy_SShape.h"
24 #include "BPy_StrokeAttribute.h"
25 #include "BPy_ViewShape.h"
26
27 #include "Iterator/BPy_AdjacencyIterator.h"
28 #include "Iterator/BPy_ChainPredicateIterator.h"
29 #include "Iterator/BPy_ChainSilhouetteIterator.h"
30 #include "Iterator/BPy_ChainingIterator.h"
31 #include "Iterator/BPy_CurvePointIterator.h"
32 #include "Iterator/BPy_Interface0DIterator.h"
33 #include "Iterator/BPy_SVertexIterator.h"
34 #include "Iterator/BPy_StrokeVertexIterator.h"
35 #include "Iterator/BPy_ViewEdgeIterator.h"
36 #include "Iterator/BPy_orientedViewEdgeIterator.h"
37
38 #include "../stroke/StrokeRep.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 ///////////////////////////////////////////////////////////////////////////////////////////
46
47 //==============================
48 // C++ => Python
49 //==============================
50
51
52 PyObject * PyBool_from_bool( bool b ){
53         return PyBool_FromLong( b ? 1 : 0);
54 }
55
56
57 PyObject * Vector_from_Vec2f( Vec2f& vec ) {
58         float vec_data[2]; // because vec->_coord is protected
59
60         vec_data[0] = vec.x();          vec_data[1] = vec.y();
61         return newVectorObject( vec_data, 2, Py_NEW, NULL);
62 }
63
64 PyObject * Vector_from_Vec3f( Vec3f& vec ) {
65         float vec_data[3]; // because vec->_coord is protected
66         
67         vec_data[0] = vec.x();          vec_data[1] = vec.y();          vec_data[2] = vec.z(); 
68         return newVectorObject( vec_data, 3, Py_NEW, NULL);
69 }
70
71 PyObject * Vector_from_Vec3r( Vec3r& vec ) {
72         float vec_data[3]; // because vec->_coord is protected
73         
74         vec_data[0] = vec.x();          vec_data[1] = vec.y();          vec_data[2] = vec.z(); 
75         return newVectorObject( vec_data, 3, Py_NEW, NULL);
76 }
77
78 PyObject * BPy_Id_from_Id( Id& id ) {
79         PyObject *py_id = Id_Type.tp_new( &Id_Type, 0, 0 );
80         ((BPy_Id *) py_id)->id = new Id( id.getFirst(), id.getSecond() );
81
82         return py_id;
83 }
84
85 PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
86         if (typeid(if0D) == typeid(CurvePoint)) {
87                 return BPy_CurvePoint_from_CurvePoint(dynamic_cast<CurvePoint&>(if0D));
88         } else if (typeid(if0D) == typeid(StrokeVertex)) {
89                 return BPy_StrokeVertex_from_StrokeVertex(dynamic_cast<StrokeVertex&>(if0D));
90         } else if (typeid(if0D) == typeid(SVertex)) {
91                 return BPy_SVertex_from_SVertex(dynamic_cast<SVertex&>(if0D));
92         } else if (typeid(if0D) == typeid(ViewVertex)) {
93                 return BPy_ViewVertex_from_ViewVertex(dynamic_cast<ViewVertex&>(if0D));
94         } else if (typeid(if0D) == typeid(NonTVertex)) {
95                 return BPy_NonTVertex_from_NonTVertex(dynamic_cast<NonTVertex&>(if0D));
96         } else if (typeid(if0D) == typeid(TVertex)) {
97                 return BPy_TVertex_from_TVertex(dynamic_cast<TVertex&>(if0D));
98         } else if (typeid(if0D) == typeid(Interface0D)) {
99                 return BPy_Interface0D_from_Interface0D(if0D);
100         }
101         string msg("unexpected type: " + if0D.getExactTypeName());
102         PyErr_SetString(PyExc_TypeError, msg.c_str());
103         return NULL;
104 }
105
106 PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D ) {
107         if (typeid(if1D) == typeid(ViewEdge)) {
108                 return BPy_ViewEdge_from_ViewEdge(dynamic_cast<ViewEdge&>(if1D));
109         } else if (typeid(if1D) == typeid(Chain)) {
110                 return BPy_Chain_from_Chain(dynamic_cast<Chain&>(if1D));
111         } else if (typeid(if1D) == typeid(Stroke)) {
112                 return BPy_Stroke_from_Stroke(dynamic_cast<Stroke&>(if1D));
113         } else if (typeid(if1D) == typeid(FEdgeSharp)) {
114                 return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast<FEdgeSharp&>(if1D));
115         } else if (typeid(if1D) == typeid(FEdgeSmooth)) {
116                 return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast<FEdgeSmooth&>(if1D));
117         } else if (typeid(if1D) == typeid(FEdge)) {
118                 return BPy_FEdge_from_FEdge(dynamic_cast<FEdge&>(if1D));
119         } else if (typeid(if1D) == typeid(Interface1D)) {
120                 return BPy_Interface1D_from_Interface1D( if1D );
121         }
122         string msg("unexpected type: " + if1D.getExactTypeName());
123         PyErr_SetString(PyExc_TypeError, msg.c_str());
124         return NULL;
125 }
126
127 PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe ) {
128         if (typeid(fe) == typeid(FEdgeSharp)) {
129                 return BPy_FEdgeSharp_from_FEdgeSharp( dynamic_cast<FEdgeSharp&>(fe) );
130         } else if (typeid(fe) == typeid(FEdgeSmooth)) {
131                 return BPy_FEdgeSmooth_from_FEdgeSmooth( dynamic_cast<FEdgeSmooth&>(fe) );
132         } else if (typeid(fe) == typeid(FEdge)) {
133                 return BPy_FEdge_from_FEdge( fe );
134         }
135         string msg("unexpected type: " + fe.getExactTypeName());
136         PyErr_SetString(PyExc_TypeError, msg.c_str());
137         return NULL;
138 }
139
140 PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv ) {
141         if (typeid(vv) == typeid(NonTVertex)) {
142                 return BPy_NonTVertex_from_NonTVertex( dynamic_cast<NonTVertex&>(vv) );
143         } else if (typeid(vv) == typeid(TVertex)) {
144                 return BPy_TVertex_from_TVertex( dynamic_cast<TVertex&>(vv) );
145         } else if (typeid(vv) == typeid(ViewVertex)) {
146                 return BPy_ViewVertex_from_ViewVertex( vv );
147         }
148         string msg("unexpected type: " + vv.getExactTypeName());
149         PyErr_SetString(PyExc_TypeError, msg.c_str());
150         return NULL;
151 }
152
153 PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
154         PyObject *py_if0D =  Interface0D_Type.tp_new( &Interface0D_Type, 0, 0 );
155         ((BPy_Interface0D *) py_if0D)->if0D = &if0D;
156         ((BPy_Interface0D *) py_if0D)->borrowed = 1;
157
158         return py_if0D;
159 }
160
161 PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ) {
162         PyObject *py_if1D =  Interface1D_Type.tp_new( &Interface1D_Type, 0, 0 );
163         ((BPy_Interface1D *) py_if1D)->if1D = &if1D;
164         ((BPy_Interface1D *) py_if1D)->borrowed = 1;
165
166         return py_if1D;
167 }
168
169 PyObject * BPy_SVertex_from_SVertex( SVertex& sv ) {
170         PyObject *py_sv = SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
171         ((BPy_SVertex *) py_sv)->sv = &sv;
172         ((BPy_SVertex *) py_sv)->py_if0D.if0D = ((BPy_SVertex *) py_sv)->sv;
173         ((BPy_SVertex *) py_sv)->py_if0D.borrowed = 1;
174
175         return py_sv;
176 }
177
178 PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes ) {
179         PyObject *py_fe = FEdgeSharp_Type.tp_new( &FEdgeSharp_Type, 0, 0 );
180         ((BPy_FEdgeSharp *) py_fe)->fes = &fes;
181         ((BPy_FEdgeSharp *) py_fe)->py_fe.fe = ((BPy_FEdgeSharp *) py_fe)->fes;
182         ((BPy_FEdgeSharp *) py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSharp *) py_fe)->fes;
183         ((BPy_FEdgeSharp *) py_fe)->py_fe.py_if1D.borrowed = 1;
184
185         return py_fe;
186 }
187
188 PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes ) {
189         PyObject *py_fe = FEdgeSmooth_Type.tp_new( &FEdgeSmooth_Type, 0, 0 );
190         ((BPy_FEdgeSmooth *) py_fe)->fes = &fes;
191         ((BPy_FEdgeSmooth *) py_fe)->py_fe.fe = ((BPy_FEdgeSmooth *) py_fe)->fes;
192         ((BPy_FEdgeSmooth *) py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSmooth *) py_fe)->fes;
193         ((BPy_FEdgeSmooth *) py_fe)->py_fe.py_if1D.borrowed = 1;
194
195         return py_fe;
196 }
197
198 PyObject * BPy_FEdge_from_FEdge( FEdge& fe ) {
199         PyObject *py_fe = FEdge_Type.tp_new( &FEdge_Type, 0, 0 );
200         ((BPy_FEdge *) py_fe)->fe = &fe;
201         ((BPy_FEdge *) py_fe)->py_if1D.if1D = ((BPy_FEdge *) py_fe)->fe;
202         ((BPy_FEdge *) py_fe)->py_if1D.borrowed = 1;
203
204         return py_fe;
205 }
206
207 PyObject * BPy_Nature_from_Nature( unsigned short n ) {
208         PyObject *py_n;
209
210         PyObject *args = PyTuple_New(1);
211         PyTuple_SetItem( args, 0, PyLong_FromLong(n) );
212         py_n =  Nature_Type.tp_new(&Nature_Type, args, NULL);
213         Py_DECREF(args);
214
215         return py_n;
216 }
217
218 PyObject * BPy_Stroke_from_Stroke( Stroke& s ) {
219         PyObject *py_s = Stroke_Type.tp_new( &Stroke_Type, 0, 0 );
220         ((BPy_Stroke *) py_s)->s = &s;
221         ((BPy_Stroke *) py_s)->py_if1D.if1D = ((BPy_Stroke *) py_s)->s;
222         ((BPy_Stroke *) py_s)->py_if1D.borrowed = 1;
223
224         return py_s;
225 }
226
227 PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa ) {
228         PyObject *py_sa = StrokeAttribute_Type.tp_new( &StrokeAttribute_Type, 0, 0 );
229         ((BPy_StrokeAttribute *) py_sa)->sa = &sa;
230         ((BPy_StrokeAttribute *) py_sa)->borrowed = 1;
231         return py_sa;   
232 }
233
234 PyObject * BPy_MediumType_from_MediumType( Stroke::MediumType n ) {
235         PyObject *py_mt;
236
237         PyObject *args = PyTuple_New(1);
238         PyTuple_SetItem( args, 0, PyLong_FromLong(n) );
239         py_mt = MediumType_Type.tp_new( &MediumType_Type, args, NULL );
240         Py_DECREF(args);
241
242         return py_mt;
243 }
244
245 PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv ) {
246         PyObject *py_sv = StrokeVertex_Type.tp_new( &StrokeVertex_Type, 0, 0 );
247         ((BPy_StrokeVertex *) py_sv)->sv = &sv;
248         ((BPy_StrokeVertex *) py_sv)->py_cp.cp = ((BPy_StrokeVertex *) py_sv)->sv;
249         ((BPy_StrokeVertex *) py_sv)->py_cp.py_if0D.if0D = ((BPy_StrokeVertex *) py_sv)->sv;
250         ((BPy_StrokeVertex *) py_sv)->py_cp.py_if0D.borrowed = 1;
251
252         return py_sv;
253 }
254
255 PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv ) {
256         PyObject *py_vv = ViewVertex_Type.tp_new( &ViewVertex_Type, 0, 0 );
257         ((BPy_ViewVertex *) py_vv)->vv = &vv;
258         ((BPy_ViewVertex *) py_vv)->py_if0D.if0D = ((BPy_ViewVertex *) py_vv)->vv;
259         ((BPy_ViewVertex *) py_vv)->py_if0D.borrowed = 1;
260
261         return py_vv;
262 }
263
264 PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv ) {
265         PyObject *py_ntv = NonTVertex_Type.tp_new( &NonTVertex_Type, 0, 0 );
266         ((BPy_NonTVertex *) py_ntv)->ntv = &ntv;
267         ((BPy_NonTVertex *) py_ntv)->py_vv.vv = ((BPy_NonTVertex *) py_ntv)->ntv;
268         ((BPy_NonTVertex *) py_ntv)->py_vv.py_if0D.if0D = ((BPy_NonTVertex *) py_ntv)->ntv;
269         ((BPy_NonTVertex *) py_ntv)->py_vv.py_if0D.borrowed = 1;
270
271         return py_ntv;
272 }
273
274 PyObject * BPy_TVertex_from_TVertex( TVertex& tv ) {
275         PyObject *py_tv = TVertex_Type.tp_new( &TVertex_Type, 0, 0 );
276         ((BPy_TVertex *) py_tv)->tv = &tv;
277         ((BPy_TVertex *) py_tv)->py_vv.vv = ((BPy_TVertex *) py_tv)->tv;
278         ((BPy_TVertex *) py_tv)->py_vv.py_if0D.if0D = ((BPy_TVertex *) py_tv)->tv;
279         ((BPy_TVertex *) py_tv)->py_vv.py_if0D.borrowed = 1;
280
281         return py_tv;
282 }
283
284 PyObject * BPy_BBox_from_BBox( BBox< Vec3r > &bb ) {
285         PyObject *py_bb = BBox_Type.tp_new( &BBox_Type, 0, 0 );
286         ((BPy_BBox *) py_bb)->bb = new BBox< Vec3r >( bb );
287
288         return py_bb;
289 }
290
291 PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve ) {
292         PyObject *py_ve = ViewEdge_Type.tp_new( &ViewEdge_Type, 0, 0 );
293         ((BPy_ViewEdge *) py_ve)->ve = &ve;
294         ((BPy_ViewEdge *) py_ve)->py_if1D.if1D = ((BPy_ViewEdge *) py_ve)->ve;
295         ((BPy_ViewEdge *) py_ve)->py_if1D.borrowed = 1;
296
297         return py_ve;
298 }
299
300 PyObject * BPy_Chain_from_Chain( Chain& c ) {
301         PyObject *py_c = Chain_Type.tp_new( &Chain_Type, 0, 0 );
302         ((BPy_Chain *) py_c)->c = &c;
303         ((BPy_Chain *) py_c)->py_c.c = ((BPy_Chain *) py_c)->c;
304         ((BPy_Chain *) py_c)->py_c.py_if1D.if1D = ((BPy_Chain *) py_c)->c;
305         ((BPy_Chain *) py_c)->py_c.py_if1D.borrowed = 1;
306         return py_c;
307 }
308
309 PyObject * BPy_SShape_from_SShape( SShape& ss ) {
310         PyObject *py_ss = SShape_Type.tp_new( &SShape_Type, 0, 0 );
311         ((BPy_SShape *) py_ss)->ss = &ss;
312         ((BPy_SShape *) py_ss)->borrowed = 1;
313
314         return py_ss;   
315 }
316
317 PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs ) {
318         PyObject *py_vs = ViewShape_Type.tp_new( &ViewShape_Type, 0, 0 );
319         ((BPy_ViewShape *) py_vs)->vs = &vs;
320         ((BPy_ViewShape *) py_vs)->borrowed = 1;
321
322         return py_vs;
323 }
324
325 PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m ){
326         PyObject *py_m = FrsMaterial_Type.tp_new( &FrsMaterial_Type, 0, 0 );
327         ((BPy_FrsMaterial*) py_m)->m = &m;
328         ((BPy_FrsMaterial*) py_m)->borrowed = 1;
329
330         return py_m;
331 }
332
333 PyObject * BPy_IntegrationType_from_IntegrationType( IntegrationType i ) {
334         PyObject *py_it;
335
336         PyObject *args = PyTuple_New(1);
337         PyTuple_SetItem( args, 0, PyLong_FromLong(i) );
338         py_it = IntegrationType_Type.tp_new( &IntegrationType_Type, args, NULL );
339         Py_DECREF(args);
340
341         return py_it;
342 }
343
344 PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp ) {
345         PyObject *py_cp = CurvePoint_Type.tp_new( &CurvePoint_Type, 0, 0 );
346         ((BPy_CurvePoint*) py_cp)->cp = &cp;
347         ((BPy_CurvePoint*) py_cp)->py_if0D.if0D = ((BPy_CurvePoint*) py_cp)->cp;
348         ((BPy_CurvePoint*) py_cp)->py_if0D.borrowed = 1;
349
350         return py_cp;
351 }
352
353 PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve ) {
354         PyObject *py_dve = PyTuple_New(2);
355         
356         PyTuple_SetItem( py_dve, 0, BPy_ViewEdge_from_ViewEdge(*(dve.first)) );
357         PyTuple_SetItem( py_dve, 1, PyBool_from_bool(dve.second) );
358         
359         return py_dve;
360 }
361
362 //==============================
363 // Iterators
364 //==============================
365
366 PyObject * BPy_AdjacencyIterator_from_AdjacencyIterator( AdjacencyIterator& a_it ) {
367         PyObject *py_a_it = AdjacencyIterator_Type.tp_new( &AdjacencyIterator_Type, 0, 0 );
368         ((BPy_AdjacencyIterator *) py_a_it)->a_it = new AdjacencyIterator( a_it );
369         ((BPy_AdjacencyIterator *) py_a_it)->py_it.it = ((BPy_AdjacencyIterator *) py_a_it)->a_it;
370
371         return py_a_it;
372 }
373
374 PyObject * BPy_Interface0DIterator_from_Interface0DIterator( Interface0DIterator& if0D_it, int reversed ) {
375         PyObject *py_if0D_it = Interface0DIterator_Type.tp_new( &Interface0DIterator_Type, 0, 0 );
376         ((BPy_Interface0DIterator *) py_if0D_it)->if0D_it = new Interface0DIterator( if0D_it );
377         ((BPy_Interface0DIterator *) py_if0D_it)->py_it.it = ((BPy_Interface0DIterator *) py_if0D_it)->if0D_it;
378         ((BPy_Interface0DIterator *) py_if0D_it)->reversed = reversed;
379
380         return py_if0D_it;
381 }
382
383 PyObject * BPy_CurvePointIterator_from_CurvePointIterator( CurveInternal::CurvePointIterator& cp_it ) {
384         PyObject *py_cp_it = CurvePointIterator_Type.tp_new( &CurvePointIterator_Type, 0, 0 );
385         ((BPy_CurvePointIterator *) py_cp_it)->cp_it = new CurveInternal::CurvePointIterator( cp_it );
386         ((BPy_CurvePointIterator *) py_cp_it)->py_it.it = ((BPy_CurvePointIterator *) py_cp_it)->cp_it;
387
388         return py_cp_it;
389 }
390
391 PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator( StrokeInternal::StrokeVertexIterator& sv_it, int reversed) {
392         PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new( &StrokeVertexIterator_Type, 0, 0 );
393         ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator( sv_it );
394         ((BPy_StrokeVertexIterator *) py_sv_it)->py_it.it = ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it;
395         ((BPy_StrokeVertexIterator *) py_sv_it)->reversed = reversed;
396
397         return py_sv_it;
398 }
399
400 PyObject * BPy_SVertexIterator_from_SVertexIterator( ViewEdgeInternal::SVertexIterator& sv_it ) {
401         PyObject *py_sv_it = SVertexIterator_Type.tp_new( &SVertexIterator_Type, 0, 0 );
402         ((BPy_SVertexIterator *) py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator( sv_it );
403         ((BPy_SVertexIterator *) py_sv_it)->py_it.it = ((BPy_SVertexIterator *) py_sv_it)->sv_it;
404         
405         return py_sv_it;
406 }
407
408
409 PyObject * BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ViewVertexInternal::orientedViewEdgeIterator& ove_it, int reversed ) {
410         PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new( &orientedViewEdgeIterator_Type, 0, 0 );
411         ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( ove_it );
412         ((BPy_orientedViewEdgeIterator *) py_ove_it)->py_it.it = ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it;
413         ((BPy_orientedViewEdgeIterator *) py_ove_it)->reversed = reversed;
414         
415         return py_ove_it;
416 }
417
418 PyObject * BPy_ViewEdgeIterator_from_ViewEdgeIterator( ViewEdgeInternal::ViewEdgeIterator& ve_it )  {
419         PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new( &ViewEdgeIterator_Type, 0, 0 );
420         ((BPy_ViewEdgeIterator *) py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator( ve_it );
421         ((BPy_ViewEdgeIterator *) py_ve_it)->py_it.it = ((BPy_ViewEdgeIterator *) py_ve_it)->ve_it;
422         
423         return py_ve_it;
424 }
425
426 PyObject * BPy_ChainingIterator_from_ChainingIterator( ChainingIterator& c_it ) {
427         PyObject *py_c_it = ChainingIterator_Type.tp_new( &ChainingIterator_Type, 0, 0 );
428         ((BPy_ChainingIterator *) py_c_it)->c_it = new ChainingIterator( c_it );
429         ((BPy_ChainingIterator *) py_c_it)->py_ve_it.py_it.it = ((BPy_ChainingIterator *) py_c_it)->c_it;
430         
431         return py_c_it;
432 }
433
434 PyObject * BPy_ChainPredicateIterator_from_ChainPredicateIterator( ChainPredicateIterator& cp_it ) {
435         PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new( &ChainPredicateIterator_Type, 0, 0 );
436         ((BPy_ChainPredicateIterator *) py_cp_it)->cp_it = new ChainPredicateIterator( cp_it );
437         ((BPy_ChainPredicateIterator *) py_cp_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainPredicateIterator *) py_cp_it)->cp_it;
438
439         return py_cp_it;
440 }
441
442 PyObject * BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator( ChainSilhouetteIterator& cs_it ) {
443         PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new( &ChainSilhouetteIterator_Type, 0, 0 );
444         ((BPy_ChainSilhouetteIterator *) py_cs_it)->cs_it = new ChainSilhouetteIterator( cs_it );
445         ((BPy_ChainSilhouetteIterator *) py_cs_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainSilhouetteIterator *) py_cs_it)->cs_it;
446
447         return py_cs_it;
448 }
449
450
451 //==============================
452 // Python => C++
453 //==============================
454
455 bool bool_from_PyBool( PyObject *b ) {
456         return PyObject_IsTrue(b) != 0;
457 }
458
459 IntegrationType IntegrationType_from_BPy_IntegrationType( PyObject* obj ) {
460         return static_cast<IntegrationType>( PyLong_AsLong(obj) );
461 }
462
463 Stroke::MediumType MediumType_from_BPy_MediumType( PyObject* obj ) {
464         return static_cast<Stroke::MediumType>( PyLong_AsLong(obj) );
465 }
466
467 Nature::EdgeNature EdgeNature_from_BPy_Nature( PyObject* obj ) {
468         return static_cast<Nature::EdgeNature>( PyLong_AsLong(obj) );
469 }
470
471 Vec2f * Vec2f_ptr_from_PyObject( PyObject* obj ) {
472         Vec2f *v;
473         if( (v = Vec2f_ptr_from_Vector( obj )) )
474                 return v;
475         if( (v = Vec2f_ptr_from_PyList( obj )) )
476                 return v;
477         if( (v = Vec2f_ptr_from_PyTuple( obj )) )
478                 return v;
479         return NULL;
480 }
481
482 Vec3f * Vec3f_ptr_from_PyObject( PyObject* obj ) {
483         Vec3f *v;
484         if( (v = Vec3f_ptr_from_Vector( obj )) )
485                 return v;
486         if( (v = Vec3f_ptr_from_PyList( obj )) )
487                 return v;
488         if( (v = Vec3f_ptr_from_PyTuple( obj )) )
489                 return v;
490         return NULL;
491 }
492
493 Vec3r * Vec3r_ptr_from_PyObject( PyObject* obj ) {
494         Vec3r *v;
495         if( (v = Vec3r_ptr_from_Vector( obj )) )
496                 return v;
497         if( (v = Vec3r_ptr_from_PyList( obj )) )
498                 return v;
499         if( (v = Vec3r_ptr_from_PyTuple( obj )) )
500                 return v;
501         return NULL;
502 }
503
504 Vec2f * Vec2f_ptr_from_Vector( PyObject* obj ) {
505         PyObject *v;
506         if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
507                 return NULL;
508         v = PyObject_GetAttrString(obj,"x");
509         float x = PyFloat_AsDouble( v );
510         Py_DECREF( v );
511         v = PyObject_GetAttrString(obj,"y");
512         float y = PyFloat_AsDouble( v );
513         Py_DECREF( v );
514         
515         return new Vec2f(x,y);
516 }
517
518 Vec3f * Vec3f_ptr_from_Vector( PyObject* obj ) {
519         PyObject *v;
520         if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
521                 return NULL;
522         v = PyObject_GetAttrString(obj,"x");
523         float x = PyFloat_AsDouble( v );
524         Py_DECREF( v );
525         v = PyObject_GetAttrString(obj,"y");
526         float y = PyFloat_AsDouble( v );
527         Py_DECREF( v );
528         v = PyObject_GetAttrString(obj,"z");
529         float z = PyFloat_AsDouble( v );
530         Py_DECREF( v );
531         
532         return new Vec3f(x,y,z);
533 }
534
535 Vec3r * Vec3r_ptr_from_Vector( PyObject* obj ) {
536         PyObject *v;
537         if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
538                 return NULL;
539         v = PyObject_GetAttrString(obj,"x");
540         double x = PyFloat_AsDouble( v );
541         Py_DECREF( v );
542         v = PyObject_GetAttrString(obj,"y");
543         double y = PyFloat_AsDouble( v );
544         Py_DECREF( v );
545         v = PyObject_GetAttrString(obj,"z");
546         double z = PyFloat_AsDouble( v );
547         Py_DECREF( v );
548         
549         return new Vec3r(x,y,z);
550 }
551
552 Vec2f * Vec2f_ptr_from_PyList( PyObject* obj ) {
553         if( !PyList_Check(obj) || PyList_Size(obj) != 2 )
554                 return NULL;
555         float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
556         float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
557         return new Vec2f(x,y);
558 }
559
560 Vec3f * Vec3f_ptr_from_PyList( PyObject* obj ) {
561         if( !PyList_Check(obj) || PyList_Size(obj) != 3 )
562                 return NULL;
563         float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
564         float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
565         float z = PyFloat_AsDouble(PyList_GetItem(obj, 2));
566         return new Vec3f(x,y,z);
567 }
568
569 Vec3r * Vec3r_ptr_from_PyList( PyObject* obj ) {
570         if( !PyList_Check(obj) || PyList_Size(obj) != 3 )
571                 return NULL;
572         float x = PyFloat_AsDouble(PyList_GetItem(obj, 0));
573         float y = PyFloat_AsDouble(PyList_GetItem(obj, 1));
574         float z = PyFloat_AsDouble(PyList_GetItem(obj, 2));
575         return new Vec3r(x,y,z);
576 }
577
578 Vec2f * Vec2f_ptr_from_PyTuple( PyObject* obj ) {
579         if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 2 )
580                 return NULL;
581         float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
582         float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
583         return new Vec2f(x,y);
584 }
585
586 Vec3f * Vec3f_ptr_from_PyTuple( PyObject* obj ) {
587         if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 )
588                 return NULL;
589         float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
590         float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
591         float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2));
592         return new Vec3f(x,y,z);
593 }
594
595 Vec3r * Vec3r_ptr_from_PyTuple( PyObject* obj ) {
596         if( !PyTuple_Check(obj) || PyTuple_Size(obj) != 3 )
597                 return NULL;
598         float x = PyFloat_AsDouble(PyTuple_GetItem(obj, 0));
599         float y = PyFloat_AsDouble(PyTuple_GetItem(obj, 1));
600         float z = PyFloat_AsDouble(PyTuple_GetItem(obj, 2));
601         return new Vec3r(x,y,z);
602 }
603
604
605 ///////////////////////////////////////////////////////////////////////////////////////////
606
607 #ifdef __cplusplus
608 }
609 #endif