2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
/** \file source/blender/freestyle/intern/python/BPy_Convert.cpp
25
#include "BPy_Convert.h"
28
#include "BPy_FrsMaterial.h"
30
#include "BPy_IntegrationType.h"
31
#include "BPy_Interface0D.h"
32
#include "Interface0D/BPy_CurvePoint.h"
33
#include "Interface0D/CurvePoint/BPy_StrokeVertex.h"
34
#include "Interface0D/BPy_SVertex.h"
35
#include "Interface0D/BPy_ViewVertex.h"
36
#include "Interface0D/ViewVertex/BPy_NonTVertex.h"
37
#include "Interface0D/ViewVertex/BPy_TVertex.h"
38
#include "BPy_Interface1D.h"
39
#include "Interface1D/BPy_FEdge.h"
40
#include "Interface1D/BPy_Stroke.h"
41
#include "Interface1D/BPy_ViewEdge.h"
42
#include "Interface1D/Curve/BPy_Chain.h"
43
#include "Interface1D/FEdge/BPy_FEdgeSharp.h"
44
#include "Interface1D/FEdge/BPy_FEdgeSmooth.h"
45
#include "BPy_Nature.h"
46
#include "BPy_MediumType.h"
47
#include "BPy_SShape.h"
48
#include "BPy_StrokeAttribute.h"
49
#include "BPy_ViewShape.h"
51
#include "Iterator/BPy_AdjacencyIterator.h"
52
#include "Iterator/BPy_ChainPredicateIterator.h"
53
#include "Iterator/BPy_ChainSilhouetteIterator.h"
54
#include "Iterator/BPy_ChainingIterator.h"
55
#include "Iterator/BPy_CurvePointIterator.h"
56
#include "Iterator/BPy_Interface0DIterator.h"
57
#include "Iterator/BPy_SVertexIterator.h"
58
#include "Iterator/BPy_StrokeVertexIterator.h"
59
#include "Iterator/BPy_ViewEdgeIterator.h"
60
#include "Iterator/BPy_orientedViewEdgeIterator.h"
62
#include "../stroke/StrokeRep.h"
68
///////////////////////////////////////////////////////////////////////////////////////////
70
//==============================
72
//==============================
74
PyObject *PyBool_from_bool(bool b)
76
return PyBool_FromLong(b ? 1 : 0);
79
PyObject *Vector_from_Vec2f(Vec2f& vec)
81
float vec_data[2]; // because vec->_coord is protected
82
vec_data[0] = vec.x();
83
vec_data[1] = vec.y();
84
return Vector_CreatePyObject(vec_data, 2, Py_NEW, NULL);
87
PyObject *Vector_from_Vec3f(Vec3f& vec)
89
float vec_data[3]; // because vec->_coord is protected
90
vec_data[0] = vec.x();
91
vec_data[1] = vec.y();
92
vec_data[2] = vec.z();
93
return Vector_CreatePyObject(vec_data, 3, Py_NEW, NULL);
96
PyObject *Vector_from_Vec3r(Vec3r& vec)
98
float vec_data[3]; // because vec->_coord is protected
99
vec_data[0] = vec.x();
100
vec_data[1] = vec.y();
101
vec_data[2] = vec.z();
102
return Vector_CreatePyObject(vec_data, 3, Py_NEW, NULL);
105
PyObject *BPy_Id_from_Id(Id& id)
107
PyObject *py_id = Id_Type.tp_new(&Id_Type, 0, 0);
108
((BPy_Id *)py_id)->id = new Id(id.getFirst(), id.getSecond());
112
PyObject *Any_BPy_Interface0D_from_Interface0D(Interface0D& if0D)
114
if (typeid(if0D) == typeid(CurvePoint)) {
115
return BPy_CurvePoint_from_CurvePoint(dynamic_cast<CurvePoint&>(if0D));
117
else if (typeid(if0D) == typeid(StrokeVertex)) {
118
return BPy_StrokeVertex_from_StrokeVertex(dynamic_cast<StrokeVertex&>(if0D));
120
else if (typeid(if0D) == typeid(SVertex)) {
121
return BPy_SVertex_from_SVertex(dynamic_cast<SVertex&>(if0D));
123
else if (typeid(if0D) == typeid(ViewVertex)) {
124
return BPy_ViewVertex_from_ViewVertex(dynamic_cast<ViewVertex&>(if0D));
126
else if (typeid(if0D) == typeid(NonTVertex)) {
127
return BPy_NonTVertex_from_NonTVertex(dynamic_cast<NonTVertex&>(if0D));
129
else if (typeid(if0D) == typeid(TVertex)) {
130
return BPy_TVertex_from_TVertex(dynamic_cast<TVertex&>(if0D));
132
else if (typeid(if0D) == typeid(Interface0D)) {
133
return BPy_Interface0D_from_Interface0D(if0D);
135
string msg("unexpected type: " + if0D.getExactTypeName());
136
PyErr_SetString(PyExc_TypeError, msg.c_str());
140
PyObject *Any_BPy_Interface1D_from_Interface1D(Interface1D& if1D)
142
if (typeid(if1D) == typeid(ViewEdge)) {
143
return BPy_ViewEdge_from_ViewEdge(dynamic_cast<ViewEdge&>(if1D));
145
else if (typeid(if1D) == typeid(Chain)) {
146
return BPy_Chain_from_Chain(dynamic_cast<Chain&>(if1D));
148
else if (typeid(if1D) == typeid(Stroke)) {
149
return BPy_Stroke_from_Stroke(dynamic_cast<Stroke&>(if1D));
151
else if (typeid(if1D) == typeid(FEdgeSharp)) {
152
return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast<FEdgeSharp&>(if1D));
154
else if (typeid(if1D) == typeid(FEdgeSmooth)) {
155
return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast<FEdgeSmooth&>(if1D));
157
else if (typeid(if1D) == typeid(FEdge)) {
158
return BPy_FEdge_from_FEdge(dynamic_cast<FEdge&>(if1D));
160
else if (typeid(if1D) == typeid(Interface1D)) {
161
return BPy_Interface1D_from_Interface1D(if1D);
163
string msg("unexpected type: " + if1D.getExactTypeName());
164
PyErr_SetString(PyExc_TypeError, msg.c_str());
168
PyObject *Any_BPy_FEdge_from_FEdge(FEdge& fe)
170
if (typeid(fe) == typeid(FEdgeSharp)) {
171
return BPy_FEdgeSharp_from_FEdgeSharp(dynamic_cast<FEdgeSharp&>(fe));
173
else if (typeid(fe) == typeid(FEdgeSmooth)) {
174
return BPy_FEdgeSmooth_from_FEdgeSmooth(dynamic_cast<FEdgeSmooth&>(fe));
176
else if (typeid(fe) == typeid(FEdge)) {
177
return BPy_FEdge_from_FEdge(fe);
179
string msg("unexpected type: " + fe.getExactTypeName());
180
PyErr_SetString(PyExc_TypeError, msg.c_str());
184
PyObject *Any_BPy_ViewVertex_from_ViewVertex(ViewVertex& vv)
186
if (typeid(vv) == typeid(NonTVertex)) {
187
return BPy_NonTVertex_from_NonTVertex(dynamic_cast<NonTVertex&>(vv));
189
else if (typeid(vv) == typeid(TVertex)) {
190
return BPy_TVertex_from_TVertex(dynamic_cast<TVertex&>(vv));
192
else if (typeid(vv) == typeid(ViewVertex)) {
193
return BPy_ViewVertex_from_ViewVertex(vv);
195
string msg("unexpected type: " + vv.getExactTypeName());
196
PyErr_SetString(PyExc_TypeError, msg.c_str());
200
PyObject *BPy_Interface0D_from_Interface0D(Interface0D& if0D)
202
PyObject *py_if0D = Interface0D_Type.tp_new(&Interface0D_Type, 0, 0);
203
((BPy_Interface0D *)py_if0D)->if0D = &if0D;
204
((BPy_Interface0D *)py_if0D)->borrowed = 1;
208
PyObject *BPy_Interface1D_from_Interface1D(Interface1D& if1D)
210
PyObject *py_if1D = Interface1D_Type.tp_new(&Interface1D_Type, 0, 0);
211
((BPy_Interface1D *)py_if1D)->if1D = &if1D;
212
((BPy_Interface1D *)py_if1D)->borrowed = 1;
216
PyObject *BPy_SVertex_from_SVertex(SVertex& sv)
218
PyObject *py_sv = SVertex_Type.tp_new(&SVertex_Type, 0, 0);
219
((BPy_SVertex *)py_sv)->sv = &sv;
220
((BPy_SVertex *)py_sv)->py_if0D.if0D = ((BPy_SVertex *)py_sv)->sv;
221
((BPy_SVertex *)py_sv)->py_if0D.borrowed = 1;
225
PyObject *BPy_FEdgeSharp_from_FEdgeSharp(FEdgeSharp& fes)
227
PyObject *py_fe = FEdgeSharp_Type.tp_new(&FEdgeSharp_Type, 0, 0);
228
((BPy_FEdgeSharp *)py_fe)->fes = &fes;
229
((BPy_FEdgeSharp *)py_fe)->py_fe.fe = ((BPy_FEdgeSharp *)py_fe)->fes;
230
((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSharp *)py_fe)->fes;
231
((BPy_FEdgeSharp *)py_fe)->py_fe.py_if1D.borrowed = 1;
235
PyObject *BPy_FEdgeSmooth_from_FEdgeSmooth(FEdgeSmooth& fes)
237
PyObject *py_fe = FEdgeSmooth_Type.tp_new(&FEdgeSmooth_Type, 0, 0);
238
((BPy_FEdgeSmooth *)py_fe)->fes = &fes;
239
((BPy_FEdgeSmooth *)py_fe)->py_fe.fe = ((BPy_FEdgeSmooth *)py_fe)->fes;
240
((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.if1D = ((BPy_FEdgeSmooth *)py_fe)->fes;
241
((BPy_FEdgeSmooth *)py_fe)->py_fe.py_if1D.borrowed = 1;
245
PyObject *BPy_FEdge_from_FEdge(FEdge& fe)
247
PyObject *py_fe = FEdge_Type.tp_new(&FEdge_Type, 0, 0);
248
((BPy_FEdge *)py_fe)->fe = &fe;
249
((BPy_FEdge *)py_fe)->py_if1D.if1D = ((BPy_FEdge *)py_fe)->fe;
250
((BPy_FEdge *)py_fe)->py_if1D.borrowed = 1;
254
PyObject *BPy_Nature_from_Nature(unsigned short n)
256
PyObject *args = PyTuple_New(1);
257
PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n));
258
PyObject *py_n = Nature_Type.tp_new(&Nature_Type, args, NULL);
263
PyObject *BPy_Stroke_from_Stroke(Stroke& s)
265
PyObject *py_s = Stroke_Type.tp_new(&Stroke_Type, 0, 0);
266
((BPy_Stroke *)py_s)->s = &s;
267
((BPy_Stroke *)py_s)->py_if1D.if1D = ((BPy_Stroke *)py_s)->s;
268
((BPy_Stroke *)py_s)->py_if1D.borrowed = 1;
272
PyObject *BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute& sa)
274
PyObject *py_sa = StrokeAttribute_Type.tp_new(&StrokeAttribute_Type, 0, 0);
275
((BPy_StrokeAttribute *)py_sa)->sa = &sa;
276
((BPy_StrokeAttribute *)py_sa)->borrowed = 1;
280
PyObject *BPy_MediumType_from_MediumType(Stroke::MediumType n)
282
PyObject *args = PyTuple_New(1);
283
PyTuple_SET_ITEM(args, 0, PyLong_FromLong(n));
284
PyObject *py_mt = MediumType_Type.tp_new(&MediumType_Type, args, NULL);
289
PyObject *BPy_StrokeVertex_from_StrokeVertex(StrokeVertex& sv)
291
PyObject *py_sv = StrokeVertex_Type.tp_new(&StrokeVertex_Type, 0, 0);
292
((BPy_StrokeVertex *)py_sv)->sv = &sv;
293
((BPy_StrokeVertex *)py_sv)->py_cp.cp = ((BPy_StrokeVertex *)py_sv)->sv;
294
((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.if0D = ((BPy_StrokeVertex *)py_sv)->sv;
295
((BPy_StrokeVertex *)py_sv)->py_cp.py_if0D.borrowed = 1;
299
PyObject *BPy_ViewVertex_from_ViewVertex(ViewVertex& vv)
301
PyObject *py_vv = ViewVertex_Type.tp_new(&ViewVertex_Type, 0, 0);
302
((BPy_ViewVertex *)py_vv)->vv = &vv;
303
((BPy_ViewVertex *)py_vv)->py_if0D.if0D = ((BPy_ViewVertex *)py_vv)->vv;
304
((BPy_ViewVertex *)py_vv)->py_if0D.borrowed = 1;
308
PyObject *BPy_NonTVertex_from_NonTVertex(NonTVertex& ntv)
310
PyObject *py_ntv = NonTVertex_Type.tp_new(&NonTVertex_Type, 0, 0);
311
((BPy_NonTVertex *)py_ntv)->ntv = &ntv;
312
((BPy_NonTVertex *)py_ntv)->py_vv.vv = ((BPy_NonTVertex *)py_ntv)->ntv;
313
((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.if0D = ((BPy_NonTVertex *)py_ntv)->ntv;
314
((BPy_NonTVertex *)py_ntv)->py_vv.py_if0D.borrowed = 1;
318
PyObject *BPy_TVertex_from_TVertex(TVertex& tv)
320
PyObject *py_tv = TVertex_Type.tp_new(&TVertex_Type, 0, 0);
321
((BPy_TVertex *)py_tv)->tv = &tv;
322
((BPy_TVertex *)py_tv)->py_vv.vv = ((BPy_TVertex *)py_tv)->tv;
323
((BPy_TVertex *)py_tv)->py_vv.py_if0D.if0D = ((BPy_TVertex *)py_tv)->tv;
324
((BPy_TVertex *)py_tv)->py_vv.py_if0D.borrowed = 1;
328
PyObject *BPy_BBox_from_BBox(const BBox< Vec3r > &bb)
330
PyObject *py_bb = BBox_Type.tp_new(&BBox_Type, 0, 0);
331
((BPy_BBox *)py_bb)->bb = new BBox< Vec3r >(bb);
335
PyObject *BPy_ViewEdge_from_ViewEdge(ViewEdge& ve)
337
PyObject *py_ve = ViewEdge_Type.tp_new(&ViewEdge_Type, 0, 0);
338
((BPy_ViewEdge *)py_ve)->ve = &ve;
339
((BPy_ViewEdge *)py_ve)->py_if1D.if1D = ((BPy_ViewEdge *)py_ve)->ve;
340
((BPy_ViewEdge *)py_ve)->py_if1D.borrowed = 1;
344
PyObject *BPy_Chain_from_Chain(Chain& c)
346
PyObject *py_c = Chain_Type.tp_new(&Chain_Type, 0, 0);
347
((BPy_Chain *)py_c)->c = &c;
348
((BPy_Chain *)py_c)->py_c.c = ((BPy_Chain *)py_c)->c;
349
((BPy_Chain *)py_c)->py_c.py_if1D.if1D = ((BPy_Chain *)py_c)->c;
350
((BPy_Chain *)py_c)->py_c.py_if1D.borrowed = 1;
354
PyObject *BPy_SShape_from_SShape(SShape& ss)
356
PyObject *py_ss = SShape_Type.tp_new(&SShape_Type, 0, 0);
357
((BPy_SShape *)py_ss)->ss = &ss;
358
((BPy_SShape *)py_ss)->borrowed = 1;
362
PyObject *BPy_ViewShape_from_ViewShape(ViewShape& vs)
364
PyObject *py_vs = ViewShape_Type.tp_new(&ViewShape_Type, 0, 0);
365
((BPy_ViewShape *)py_vs)->vs = &vs;
366
((BPy_ViewShape *)py_vs)->borrowed = 1;
367
((BPy_ViewShape *)py_vs)->py_ss = NULL;
371
PyObject *BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial& m)
373
PyObject *py_m = FrsMaterial_Type.tp_new(&FrsMaterial_Type, 0, 0);
374
((BPy_FrsMaterial *) py_m)->m = new FrsMaterial(m);
378
PyObject *BPy_IntegrationType_from_IntegrationType(IntegrationType i)
380
PyObject *args = PyTuple_New(1);
381
PyTuple_SET_ITEM(args, 0, PyLong_FromLong(i));
382
PyObject *py_it = IntegrationType_Type.tp_new(&IntegrationType_Type, args, NULL);
387
PyObject *BPy_CurvePoint_from_CurvePoint(CurvePoint& cp)
389
PyObject *py_cp = CurvePoint_Type.tp_new(&CurvePoint_Type, 0, 0);
390
((BPy_CurvePoint *) py_cp)->cp = &cp;
391
((BPy_CurvePoint *) py_cp)->py_if0D.if0D = ((BPy_CurvePoint *)py_cp)->cp;
392
((BPy_CurvePoint *) py_cp)->py_if0D.borrowed = 1;
396
PyObject *BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge& dve)
398
PyObject *py_dve = PyTuple_New(2);
399
PyTuple_SET_ITEM(py_dve, 0, BPy_ViewEdge_from_ViewEdge(*(dve.first)));
400
PyTuple_SET_ITEM(py_dve, 1, PyBool_from_bool(dve.second));
404
//==============================
406
//==============================
408
PyObject *BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator& a_it)
410
PyObject *py_a_it = AdjacencyIterator_Type.tp_new(&AdjacencyIterator_Type, 0, 0);
411
((BPy_AdjacencyIterator *)py_a_it)->a_it = new AdjacencyIterator(a_it);
412
((BPy_AdjacencyIterator *)py_a_it)->py_it.it = ((BPy_AdjacencyIterator *)py_a_it)->a_it;
416
PyObject *BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator& if0D_it, int reversed)
418
PyObject *py_if0D_it = Interface0DIterator_Type.tp_new(&Interface0DIterator_Type, 0, 0);
419
((BPy_Interface0DIterator *)py_if0D_it)->if0D_it = new Interface0DIterator(if0D_it);
420
((BPy_Interface0DIterator *)py_if0D_it)->py_it.it = ((BPy_Interface0DIterator *)py_if0D_it)->if0D_it;
421
((BPy_Interface0DIterator *)py_if0D_it)->reversed = reversed;
425
PyObject *BPy_CurvePointIterator_from_CurvePointIterator(CurveInternal::CurvePointIterator& cp_it)
427
PyObject *py_cp_it = CurvePointIterator_Type.tp_new(&CurvePointIterator_Type, 0, 0);
428
((BPy_CurvePointIterator *)py_cp_it)->cp_it = new CurveInternal::CurvePointIterator(cp_it);
429
((BPy_CurvePointIterator *)py_cp_it)->py_it.it = ((BPy_CurvePointIterator *)py_cp_it)->cp_it;
433
PyObject *BPy_StrokeVertexIterator_from_StrokeVertexIterator(StrokeInternal::StrokeVertexIterator& sv_it, int reversed)
435
PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new(&StrokeVertexIterator_Type, 0, 0);
436
((BPy_StrokeVertexIterator *)py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator(sv_it);
437
((BPy_StrokeVertexIterator *)py_sv_it)->py_it.it = ((BPy_StrokeVertexIterator *)py_sv_it)->sv_it;
438
((BPy_StrokeVertexIterator *)py_sv_it)->reversed = reversed;
442
PyObject *BPy_SVertexIterator_from_SVertexIterator(ViewEdgeInternal::SVertexIterator& sv_it)
444
PyObject *py_sv_it = SVertexIterator_Type.tp_new(&SVertexIterator_Type, 0, 0);
445
((BPy_SVertexIterator *)py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator(sv_it);
446
((BPy_SVertexIterator *)py_sv_it)->py_it.it = ((BPy_SVertexIterator *)py_sv_it)->sv_it;
450
PyObject *BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ViewVertexInternal::orientedViewEdgeIterator& ove_it, int reversed)
452
PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new(&orientedViewEdgeIterator_Type, 0, 0);
453
((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(ove_it);
454
((BPy_orientedViewEdgeIterator *)py_ove_it)->py_it.it = ((BPy_orientedViewEdgeIterator *)py_ove_it)->ove_it;
455
((BPy_orientedViewEdgeIterator *)py_ove_it)->reversed = reversed;
459
PyObject *BPy_ViewEdgeIterator_from_ViewEdgeIterator(ViewEdgeInternal::ViewEdgeIterator& ve_it)
461
PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new(&ViewEdgeIterator_Type, 0, 0);
462
((BPy_ViewEdgeIterator *)py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator(ve_it);
463
((BPy_ViewEdgeIterator *)py_ve_it)->py_it.it = ((BPy_ViewEdgeIterator *)py_ve_it)->ve_it;
467
PyObject *BPy_ChainingIterator_from_ChainingIterator(ChainingIterator& c_it)
469
PyObject *py_c_it = ChainingIterator_Type.tp_new(&ChainingIterator_Type, 0, 0);
470
((BPy_ChainingIterator *)py_c_it)->c_it = new ChainingIterator(c_it);
471
((BPy_ChainingIterator *)py_c_it)->py_ve_it.py_it.it = ((BPy_ChainingIterator *)py_c_it)->c_it;
475
PyObject *BPy_ChainPredicateIterator_from_ChainPredicateIterator(ChainPredicateIterator& cp_it)
477
PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new(&ChainPredicateIterator_Type, 0, 0);
478
((BPy_ChainPredicateIterator *)py_cp_it)->cp_it = new ChainPredicateIterator(cp_it);
479
((BPy_ChainPredicateIterator *)py_cp_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainPredicateIterator *)py_cp_it)->cp_it;
483
PyObject *BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator(ChainSilhouetteIterator& cs_it)
485
PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new(&ChainSilhouetteIterator_Type, 0, 0);
486
((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it = new ChainSilhouetteIterator(cs_it);
487
((BPy_ChainSilhouetteIterator *)py_cs_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainSilhouetteIterator *)py_cs_it)->cs_it;
491
//==============================
493
//==============================
495
bool bool_from_PyBool(PyObject *b)
497
return PyObject_IsTrue(b) != 0;
500
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
502
return static_cast<IntegrationType>(PyLong_AsLong(obj));
505
Stroke::MediumType MediumType_from_BPy_MediumType(PyObject *obj)
507
return static_cast<Stroke::MediumType>(PyLong_AsLong(obj));
510
Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj)
512
return static_cast<Nature::EdgeNature>(PyLong_AsLong(obj));
515
Vec2f *Vec2f_ptr_from_PyObject(PyObject *obj)
518
if ((v = Vec2f_ptr_from_Vector(obj)))
520
if ((v = Vec2f_ptr_from_PyList(obj)))
522
if ((v = Vec2f_ptr_from_PyTuple(obj)))
527
Vec3f *Vec3f_ptr_from_PyObject(PyObject *obj)
530
if ((v = Vec3f_ptr_from_Vector(obj)))
532
if ((v = Vec3f_ptr_from_Color(obj)))
534
if ((v = Vec3f_ptr_from_PyList(obj)))
536
if ((v = Vec3f_ptr_from_PyTuple(obj)))
541
Vec3r *Vec3r_ptr_from_PyObject(PyObject *obj)
544
if ((v = Vec3r_ptr_from_Vector(obj)))
546
if ((v = Vec3r_ptr_from_Color(obj)))
548
if ((v = Vec3r_ptr_from_PyList(obj)))
550
if ((v = Vec3r_ptr_from_PyTuple(obj)))
555
Vec2f *Vec2f_ptr_from_Vector(PyObject *obj)
557
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
559
float x = ((VectorObject *)obj)->vec[0];
560
float y = ((VectorObject *)obj)->vec[1];
561
return new Vec2f(x, y);
564
Vec3f *Vec3f_ptr_from_Vector(PyObject *obj)
566
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
568
float x = ((VectorObject *)obj)->vec[0];
569
float y = ((VectorObject *)obj)->vec[1];
570
float z = ((VectorObject *)obj)->vec[2];
571
return new Vec3f(x, y, z);
574
Vec3r *Vec3r_ptr_from_Vector(PyObject *obj)
576
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
578
real x = ((VectorObject *)obj)->vec[0];
579
real y = ((VectorObject *)obj)->vec[1];
580
real z = ((VectorObject *)obj)->vec[2];
581
return new Vec3r(x, y, z);
584
Vec3f *Vec3f_ptr_from_Color(PyObject *obj)
586
if (!ColorObject_Check(obj))
588
float r = ((ColorObject *)obj)->col[0];
589
float g = ((ColorObject *)obj)->col[1];
590
float b = ((ColorObject *)obj)->col[2];
591
return new Vec3f(r, g, b);
594
Vec3r *Vec3r_ptr_from_Color(PyObject *obj)
596
if (!ColorObject_Check(obj))
598
real r = ((ColorObject *)obj)->col[0];
599
real g = ((ColorObject *)obj)->col[1];
600
real b = ((ColorObject *)obj)->col[2];
601
return new Vec3r(r, g, b);
604
static int float_array_from_PyList(PyObject *obj, float *v, int n)
606
for (int i = 0; i < n; i++) {
607
v[i] = PyFloat_AsDouble(PyList_GetItem(obj, i));
608
if (v[i] == -1.0f && PyErr_Occurred()) {
609
PyErr_SetString(PyExc_TypeError, "list elements must be a number");
616
Vec2f *Vec2f_ptr_from_PyList(PyObject *obj)
620
if (!PyList_Check(obj) || PyList_Size(obj) != 2)
622
if (!float_array_from_PyList(obj, v, 2))
624
return new Vec2f(v[0], v[1]);
627
Vec3f *Vec3f_ptr_from_PyList(PyObject *obj)
631
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
633
if (!float_array_from_PyList(obj, v, 3))
635
return new Vec3f(v[0], v[1], v[2]);
638
Vec3r *Vec3r_ptr_from_PyList(PyObject *obj)
642
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
644
if (!float_array_from_PyList(obj, v, 3))
646
return new Vec3r(v[0], v[1], v[2]);
649
static int float_array_from_PyTuple(PyObject *obj, float *v, int n)
651
for (int i = 0; i < n; i++) {
652
v[i] = PyFloat_AsDouble(PyTuple_GetItem(obj, i));
653
if (v[i] == -1.0f && PyErr_Occurred()) {
654
PyErr_SetString(PyExc_TypeError, "tuple elements must be a number");
661
Vec2f *Vec2f_ptr_from_PyTuple(PyObject *obj)
665
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2)
667
if (!float_array_from_PyTuple(obj, v, 2))
669
return new Vec2f(v[0], v[1]);
672
Vec3f *Vec3f_ptr_from_PyTuple(PyObject *obj)
676
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
678
if (!float_array_from_PyTuple(obj, v, 3))
680
return new Vec3f(v[0], v[1], v[2]);
683
Vec3r *Vec3r_ptr_from_PyTuple(PyObject *obj)
687
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
689
if (!float_array_from_PyTuple(obj, v, 3))
691
return new Vec3r(v[0], v[1], v[2]);
694
// helper for argument parsing
696
int float_array_from_PyObject(PyObject *obj, float *v, int n)
698
if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) {
699
for (int i = 0; i < n; i++)
700
v[i] = ((VectorObject *)obj)->vec[i];
703
else if (PyList_Check(obj) && PyList_Size(obj) == n) {
704
return float_array_from_PyList(obj, v, n);
706
else if (PyTuple_Check(obj) && PyTuple_Size(obj) == n) {
707
return float_array_from_PyTuple(obj, v, n);
712
///////////////////////////////////////////////////////////////////////////////////////////