d1a8fbef6b959d38113444701ea985e19d4e332b
[blender.git] / source / blender / freestyle / intern / python / Iterator / BPy_CurvePointIterator.cpp
1 #include "BPy_CurvePointIterator.h"
2
3 #include "../BPy_Convert.h"
4 #include "BPy_Interface0DIterator.h"
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 ///////////////////////////////////////////////////////////////////////////////////////////
11
12 //------------------------INSTANCE METHODS ----------------------------------
13
14 static char CurvePointIterator___doc__[] =
15 "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n"
16 "\n"
17 "Class representing an iterator on a curve.  Allows an iterating\n"
18 "outside initial vertices.  A CurvePoint is instanciated and returned\n"
19 "by getObject().\n"
20 "\n"
21 ".. method:: __init__(step=0.0)\n"
22 "\n"
23 "   Builds a CurvePointIterator object.\n"
24 "\n"
25 "   :arg step: A resampling resolution with which the curve is resampled.\n"
26 "      If zero, no resampling is done (i.e., the iterator iterates over\n"
27 "      initial vertices).\n"
28 "   :type step: float\n"
29 "\n"
30 ".. method:: __init__(brother)\n"
31 "\n"
32 "   Copy constructor.\n"
33 "\n"
34 "   :arg brother: A CurvePointIterator object.\n"
35 "   :type brother: :class:`CurvePointIterator`\n";
36
37 static int CurvePointIterator___init__(BPy_CurvePointIterator *self, PyObject *args )
38 {       
39         PyObject *obj = 0;
40
41         if (! PyArg_ParseTuple(args, "|O", &obj) )
42             return -1;
43
44         if( !obj ){
45                 self->cp_it = new CurveInternal::CurvePointIterator();
46                 
47         } else if( BPy_CurvePointIterator_Check(obj) ) {
48                 self->cp_it = new CurveInternal::CurvePointIterator(*( ((BPy_CurvePointIterator *) obj)->cp_it ));
49         
50         } else if( PyFloat_Check(obj) ) {
51                 self->cp_it = new CurveInternal::CurvePointIterator( PyFloat_AsDouble(obj) );
52                         
53         } else {
54                 PyErr_SetString(PyExc_TypeError, "invalid argument");
55                 return -1;
56         }
57
58         self->py_it.it = self->cp_it;
59
60         return 0;
61 }
62
63 static char CurvePointIterator_t___doc__[] =
64 ".. method:: t()\n"
65 "\n"
66 "   Returns the curvilinear abscissa.\n"
67 "\n"
68 "   :return: The curvilinear abscissa.\n"
69 "   :rtype: float\n";
70
71 PyObject * CurvePointIterator_t( BPy_CurvePointIterator *self ) {
72         return PyFloat_FromDouble( self->cp_it->t() );
73 }
74
75 static char CurvePointIterator_u___doc__[] =
76 ".. method:: u()\n"
77 "\n"
78 "   Returns the point parameter in the curve (0<=u<=1).\n"
79 "\n"
80 "   :return: The point parameter.\n"
81 "   :rtype: float\n";
82
83 static PyObject * CurvePointIterator_u( BPy_CurvePointIterator *self ) {
84         return PyFloat_FromDouble( self->cp_it->u() );
85 }
86
87 static char CurvePointIterator_castToInterface0DIterator___doc__[] =
88 ".. method:: castToInterface0DIterator()\n"
89 "\n"
90 "   Returns an Interface0DIterator converted from this\n"
91 "   CurvePointIterator.  Useful for any call to a function of the\n"
92 "   UnaryFunction0D type.\n"
93 "\n"
94 "   :return: An Interface0DIterator object converted from the\n"
95 "      iterator.\n"
96 "   :rtype: :class:`Interface0DIterator`\n";
97
98 static PyObject * CurvePointIterator_castToInterface0DIterator( BPy_CurvePointIterator *self ) {
99         Interface0DIterator it( self->cp_it->castToInterface0DIterator() );
100         return BPy_Interface0DIterator_from_Interface0DIterator( it, 0 );
101 }
102
103 static char CurvePointIterator_getObject___doc__[] =
104 ".. method:: getObject()\n"
105 "\n"
106 "   Returns a CurvePoint pointed by the iterator.\n"
107 "\n"
108 "   :return: \n"
109 "   :rtype: :class:`CurvePoint`\n";
110
111 static PyObject * CurvePointIterator_getObject(BPy_CurvePointIterator *self) {
112         return BPy_CurvePoint_from_CurvePoint( self->cp_it->operator*() );
113 }
114
115 /*----------------------CurvePointIterator instance definitions ----------------------------*/
116 static PyMethodDef BPy_CurvePointIterator_methods[] = {
117         {"t", ( PyCFunction ) CurvePointIterator_t, METH_NOARGS, CurvePointIterator_t___doc__},
118         {"u", ( PyCFunction ) CurvePointIterator_u, METH_NOARGS, CurvePointIterator_u___doc__},
119         {"castToInterface0DIterator", ( PyCFunction ) CurvePointIterator_castToInterface0DIterator, METH_NOARGS, CurvePointIterator_castToInterface0DIterator___doc__},
120         {"getObject", ( PyCFunction ) CurvePointIterator_getObject, METH_NOARGS, CurvePointIterator_getObject___doc__},
121         {NULL, NULL, 0, NULL}
122 };
123
124 /*-----------------------BPy_CurvePointIterator type definition ------------------------------*/
125
126 PyTypeObject CurvePointIterator_Type = {
127         PyVarObject_HEAD_INIT(NULL, 0)
128         "CurvePointIterator",           /* tp_name */
129         sizeof(BPy_CurvePointIterator), /* tp_basicsize */
130         0,                              /* tp_itemsize */
131         0,                              /* tp_dealloc */
132         0,                              /* tp_print */
133         0,                              /* tp_getattr */
134         0,                              /* tp_setattr */
135         0,                              /* tp_reserved */
136         0,                              /* tp_repr */
137         0,                              /* tp_as_number */
138         0,                              /* tp_as_sequence */
139         0,                              /* tp_as_mapping */
140         0,                              /* tp_hash  */
141         0,                              /* tp_call */
142         0,                              /* tp_str */
143         0,                              /* tp_getattro */
144         0,                              /* tp_setattro */
145         0,                              /* tp_as_buffer */
146         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
147         CurvePointIterator___doc__,     /* tp_doc */
148         0,                              /* tp_traverse */
149         0,                              /* tp_clear */
150         0,                              /* tp_richcompare */
151         0,                              /* tp_weaklistoffset */
152         0,                              /* tp_iter */
153         0,                              /* tp_iternext */
154         BPy_CurvePointIterator_methods, /* tp_methods */
155         0,                              /* tp_members */
156         0,                              /* tp_getset */
157         &Iterator_Type,                 /* tp_base */
158         0,                              /* tp_dict */
159         0,                              /* tp_descr_get */
160         0,                              /* tp_descr_set */
161         0,                              /* tp_dictoffset */
162         (initproc)CurvePointIterator___init__, /* tp_init */
163         0,                              /* tp_alloc */
164         0,                              /* tp_new */
165 };
166
167 ///////////////////////////////////////////////////////////////////////////////////////////
168
169 #ifdef __cplusplus
170 }
171 #endif