1 #include "BPy_StrokeAttribute.h"
3 #include "BPy_Convert.h"
9 ///////////////////////////////////////////////////////////////////////////////////////////
11 /*--------------- Python API function prototypes for StrokeAttribute instance -----------*/
12 static int StrokeAttribute___init__(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds);
13 static void StrokeAttribute___dealloc__(BPy_StrokeAttribute *self);
14 static PyObject * StrokeAttribute___repr__(BPy_StrokeAttribute *self);
16 static PyObject * StrokeAttribute_getColorR( BPy_StrokeAttribute *self );
17 static PyObject * StrokeAttribute_getColorG( BPy_StrokeAttribute *self );
18 static PyObject * StrokeAttribute_getColorB( BPy_StrokeAttribute *self );
19 static PyObject * StrokeAttribute_getColorRGB( BPy_StrokeAttribute *self );
20 static PyObject * StrokeAttribute_getAlpha( BPy_StrokeAttribute *self );
21 static PyObject * StrokeAttribute_getThicknessR( BPy_StrokeAttribute *self );
22 static PyObject * StrokeAttribute_getThicknessL( BPy_StrokeAttribute *self );
23 static PyObject * StrokeAttribute_getThicknessRL( BPy_StrokeAttribute *self );
24 static PyObject * StrokeAttribute_isVisible( BPy_StrokeAttribute *self );
25 static PyObject * StrokeAttribute_getAttributeReal( BPy_StrokeAttribute *self, PyObject *args );
26 static PyObject * StrokeAttribute_getAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args );
27 static PyObject * StrokeAttribute_getAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args );
28 static PyObject * StrokeAttribute_isAttributeAvailableReal( BPy_StrokeAttribute *self, PyObject *args );
29 static PyObject * StrokeAttribute_isAttributeAvailableVec2f( BPy_StrokeAttribute *self, PyObject *args );
30 static PyObject * StrokeAttribute_isAttributeAvailableVec3f( BPy_StrokeAttribute *self, PyObject *args );
31 static PyObject * StrokeAttribute_setColor( BPy_StrokeAttribute *self, PyObject *args );
32 static PyObject * StrokeAttribute_setAlpha( BPy_StrokeAttribute *self, PyObject *args );
33 static PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *args );
34 static PyObject * StrokeAttribute_setVisible( BPy_StrokeAttribute *self, PyObject *args );
35 static PyObject * StrokeAttribute_setAttributeReal( BPy_StrokeAttribute *self, PyObject *args );
36 static PyObject * StrokeAttribute_setAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args );
37 static PyObject * StrokeAttribute_setAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args );
40 /*----------------------StrokeAttribute instance definitions ----------------------------*/
41 static PyMethodDef BPy_StrokeAttribute_methods[] = {
42 {"getColorR", ( PyCFunction ) StrokeAttribute_getColorR, METH_NOARGS, "Returns the R color component. "},
43 {"getColorG", ( PyCFunction ) StrokeAttribute_getColorG, METH_NOARGS, "Returns the G color component. "},
44 {"getColorB", ( PyCFunction ) StrokeAttribute_getColorB, METH_NOARGS, "Returns the B color component. "},
45 {"getColorRGB", ( PyCFunction ) StrokeAttribute_getColorRGB, METH_NOARGS, "Returns the RGB color components."},
46 {"getAlpha", ( PyCFunction ) StrokeAttribute_getAlpha, METH_NOARGS, "Returns the alpha color component."},
47 {"getThicknessR", ( PyCFunction ) StrokeAttribute_getThicknessR, METH_NOARGS, "Returns the thickness on the right of the vertex when following the stroke. "},
48 {"getThicknessL", ( PyCFunction ) StrokeAttribute_getThicknessL, METH_NOARGS, "Returns the thickness on the left of the vertex when following the stroke."},
49 {"getThicknessRL", ( PyCFunction ) StrokeAttribute_getThicknessRL, METH_NOARGS, "Returns the thickness on the right and on the left of the vertex when following the stroke. "},
50 {"isVisible", ( PyCFunction ) StrokeAttribute_isVisible, METH_NOARGS, "Returns true if the strokevertex is visible, false otherwise"},
51 {"getAttributeReal", ( PyCFunction ) StrokeAttribute_getAttributeReal, METH_VARARGS, "(name) Returns an attribute of type real specified by name."},
52 {"getAttributeVec2f", ( PyCFunction ) StrokeAttribute_getAttributeVec2f, METH_VARARGS, "(name) Returns an attribute of type Vec2f specified by name."},
53 {"getAttributeVec3f", ( PyCFunction ) StrokeAttribute_getAttributeVec3f, METH_VARARGS, "(name) Returns an attribute of type Vec3f specified by name."},
54 {"isAttributeAvailableReal", ( PyCFunction ) StrokeAttribute_isAttributeAvailableReal, METH_VARARGS, "(name) Checks whether the real attribute specified by name is available"},
55 {"isAttributeAvailableVec2f", ( PyCFunction ) StrokeAttribute_isAttributeAvailableVec2f, METH_VARARGS, "(name) Checks whether the Vec2f attribute specified by name is available"},
56 {"isAttributeAvailableVec3f", ( PyCFunction ) StrokeAttribute_isAttributeAvailableVec3f, METH_VARARGS, "(name) Checks whether the Vec3f attribute specified by name is available"},
57 {"setColor", ( PyCFunction ) StrokeAttribute_setColor, METH_VARARGS, "(float a)Sets the attribute's alpha value. "},
58 {"setAlpha", ( PyCFunction ) StrokeAttribute_setAlpha, METH_VARARGS, "(float a) Sets the attribute's alpha value."},
59 {"setThickness", ( PyCFunction ) StrokeAttribute_setThickness, METH_VARARGS, ""},
60 {"setVisible", ( PyCFunction ) StrokeAttribute_setVisible, METH_VARARGS, ""},
61 {"setAttributeReal", ( PyCFunction ) StrokeAttribute_setAttributeReal, METH_VARARGS, "(name, float att) Adds a user defined attribute of type real. If there is no attribute of specified by name, it is added. Otherwise, the new value replaces the old one."},
62 {"setAttributeVec2f", ( PyCFunction ) StrokeAttribute_setAttributeVec2f, METH_VARARGS, "(name, float att) Adds a user defined attribute of type Vec2f. If there is no attribute of specified by name, it is added. Otherwise, the new value replaces the old one."},
63 {"setAttributeVec3f", ( PyCFunction ) StrokeAttribute_setAttributeVec3f, METH_VARARGS, "(name, float att) Adds a user defined attribute of type Vec4f. If there is no attribute of specified by name, it is added. Otherwise, the new value replaces the old one."},
69 /*-----------------------BPy_StrokeAttribute type definition ------------------------------*/
71 PyTypeObject StrokeAttribute_Type = {
72 PyVarObject_HEAD_INIT(NULL, 0)
73 "StrokeAttribute", /* tp_name */
74 sizeof(BPy_StrokeAttribute), /* tp_basicsize */
76 (destructor)StrokeAttribute___dealloc__, /* tp_dealloc */
81 (reprfunc)StrokeAttribute___repr__, /* tp_repr */
83 0, /* tp_as_sequence */
84 0, /* tp_as_mapping */
91 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
92 "StrokeAttribute objects", /* tp_doc */
95 0, /* tp_richcompare */
96 0, /* tp_weaklistoffset */
99 BPy_StrokeAttribute_methods, /* tp_methods */
104 0, /* tp_descr_get */
105 0, /* tp_descr_set */
106 0, /* tp_dictoffset */
107 (initproc)StrokeAttribute___init__, /* tp_init */
109 PyType_GenericNew, /* tp_new */
112 //-------------------MODULE INITIALIZATION--------------------------------
113 int StrokeAttribute_Init( PyObject *module )
118 if( PyType_Ready( &StrokeAttribute_Type ) < 0 )
120 Py_INCREF( &StrokeAttribute_Type );
121 PyModule_AddObject(module, "StrokeAttribute", (PyObject *)&StrokeAttribute_Type);
125 //------------------------INSTANCE METHODS ----------------------------------
127 int StrokeAttribute___init__(BPy_StrokeAttribute *self, PyObject *args, PyObject *kwds)
130 PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0, *obj4 = 0, *obj5 = 0 , *obj6 = 0;
132 if (! PyArg_ParseTuple(args, "|OOOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) )
135 if( !obj1 || !obj2 || !obj3 ){
137 self->sa = new StrokeAttribute();
139 } else if( BPy_StrokeAttribute_Check(obj1) &&
140 BPy_StrokeAttribute_Check(obj2) &&
141 PyFloat_Check(obj3) ) {
143 self->sa = new StrokeAttribute( *( ((BPy_StrokeAttribute *) obj1)->sa ),
144 *( ((BPy_StrokeAttribute *) obj2)->sa ),
145 PyFloat_AsDouble( obj3 ) );
147 } else if( obj4 && obj5 && obj6 ) {
149 self->sa = new StrokeAttribute( PyFloat_AsDouble( obj1 ),
150 PyFloat_AsDouble( obj2 ),
151 PyFloat_AsDouble( obj3 ),
152 PyFloat_AsDouble( obj4 ),
153 PyFloat_AsDouble( obj5 ),
154 PyFloat_AsDouble( obj6 ) );
157 PyErr_SetString(PyExc_TypeError, "invalid arguments");
167 void StrokeAttribute___dealloc__(BPy_StrokeAttribute* self)
169 if( self->sa && !self->borrowed )
171 Py_TYPE(self)->tp_free((PyObject*)self);
174 PyObject * StrokeAttribute___repr__(BPy_StrokeAttribute* self)
176 stringstream repr("StrokeAttribute:");
177 repr << " r: " << self->sa->getColorR()
178 << " g: " << self->sa->getColorG()
179 << " b: " << self->sa->getColorB()
180 << " a: " << self->sa->getAlpha()
181 << " - R: " << self->sa->getThicknessR()
182 << " L: " << self->sa->getThicknessL();
184 return PyUnicode_FromFormat( repr.str().c_str() );
188 PyObject *StrokeAttribute_getColorR( BPy_StrokeAttribute *self ) {
189 return PyFloat_FromDouble( self->sa->getColorR() );
192 PyObject *StrokeAttribute_getColorG( BPy_StrokeAttribute *self ) {
193 return PyFloat_FromDouble( self->sa->getColorG() );
196 PyObject *StrokeAttribute_getColorB( BPy_StrokeAttribute *self ) {
197 return PyFloat_FromDouble( self->sa->getColorB() );
200 PyObject *StrokeAttribute_getColorRGB( BPy_StrokeAttribute *self ) {
201 Vec3f v( self->sa->getColorRGB() );
202 return Vector_from_Vec3f( v );
205 PyObject *StrokeAttribute_getAlpha( BPy_StrokeAttribute *self ) {
206 return PyFloat_FromDouble( self->sa->getAlpha() );
209 PyObject *StrokeAttribute_getThicknessR( BPy_StrokeAttribute *self ) {
210 return PyFloat_FromDouble( self->sa->getThicknessR() );
212 PyObject *StrokeAttribute_getThicknessL( BPy_StrokeAttribute *self ) {
213 return PyFloat_FromDouble( self->sa->getThicknessL() );
215 PyObject *StrokeAttribute_getThicknessRL( BPy_StrokeAttribute *self ) {
216 Vec2f v( self->sa->getThicknessRL() );
217 return Vector_from_Vec2f( v );
220 PyObject *StrokeAttribute_isVisible( BPy_StrokeAttribute *self ) {
221 return PyBool_from_bool( self->sa->isVisible() );
225 PyObject *StrokeAttribute_getAttributeReal( BPy_StrokeAttribute *self, PyObject *args ) {
228 if(!( PyArg_ParseTuple(args, "s", &attr) ))
231 double a = self->sa->getAttributeReal( attr );
232 return PyFloat_FromDouble( a );
235 PyObject *StrokeAttribute_getAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
238 if(!( PyArg_ParseTuple(args, "s", &attr) ))
241 Vec2f a = self->sa->getAttributeVec2f( attr );
242 return Vector_from_Vec2f( a );
246 PyObject *StrokeAttribute_getAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
249 if(!( PyArg_ParseTuple(args, "s", &attr) ))
252 Vec3f a = self->sa->getAttributeVec3f( attr );
253 return Vector_from_Vec3f( a );
256 PyObject *StrokeAttribute_isAttributeAvailableReal( BPy_StrokeAttribute *self, PyObject *args ) {
259 if(!( PyArg_ParseTuple(args, "s", &attr) ))
262 return PyBool_from_bool( self->sa->isAttributeAvailableReal( attr ) );
265 PyObject *StrokeAttribute_isAttributeAvailableVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
268 if(!( PyArg_ParseTuple(args, "s", &attr) ))
271 return PyBool_from_bool( self->sa->isAttributeAvailableVec2f( attr ) );
274 PyObject *StrokeAttribute_isAttributeAvailableVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
277 if(!( PyArg_ParseTuple(args, "s", &attr) ))
280 return PyBool_from_bool( self->sa->isAttributeAvailableVec3f( attr ) );
284 PyObject * StrokeAttribute_setColor( BPy_StrokeAttribute *self, PyObject *args ) {
285 PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0 ;
287 if(!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
290 if( obj1 && !obj2 && !obj3 ){
292 Vec3f *v = Vec3f_ptr_from_PyObject(obj1);
294 PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)");
297 self->sa->setColor( *v );
300 } else if( obj1 && obj2 && obj3 ){
302 self->sa->setColor( PyFloat_AsDouble(obj1),
303 PyFloat_AsDouble(obj2),
304 PyFloat_AsDouble(obj3) );
307 PyErr_SetString(PyExc_TypeError, "invalid arguments");
314 PyObject * StrokeAttribute_setAlpha( BPy_StrokeAttribute *self, PyObject *args ){
317 if(!( PyArg_ParseTuple(args, "f", &f) ))
320 self->sa->setAlpha( f );
324 PyObject * StrokeAttribute_setThickness( BPy_StrokeAttribute *self, PyObject *args ) {
325 PyObject *obj1 = 0, *obj2 = 0;
327 if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) ))
332 Vec2f *v = Vec2f_ptr_from_PyObject(obj1);
334 PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)");
337 self->sa->setThickness( *v );
340 } else if( obj1 && obj2 ){
342 self->sa->setThickness( PyFloat_AsDouble(obj1),
343 PyFloat_AsDouble(obj2) );
346 PyErr_SetString(PyExc_TypeError, "invalid arguments");
353 PyObject * StrokeAttribute_setVisible( BPy_StrokeAttribute *self, PyObject *args ) {
356 if(!( PyArg_ParseTuple(args, "O", &py_b) ))
359 self->sa->setVisible( bool_from_PyBool(py_b) );
365 PyObject * StrokeAttribute_setAttributeReal( BPy_StrokeAttribute *self, PyObject *args ) {
369 if(!( PyArg_ParseTuple(args, "sd", &s, &d) ))
372 self->sa->setAttributeReal( s, d );
376 PyObject * StrokeAttribute_setAttributeVec2f( BPy_StrokeAttribute *self, PyObject *args ) {
380 if(!( PyArg_ParseTuple(args, "sO", &s, &obj) ))
382 Vec2f *v = Vec2f_ptr_from_PyObject(obj);
384 PyErr_SetString(PyExc_TypeError, "argument 2 must be a 2D vector (either a list of 2 elements or Vector)");
387 self->sa->setAttributeVec2f( s, *v );
393 PyObject * StrokeAttribute_setAttributeVec3f( BPy_StrokeAttribute *self, PyObject *args ) {
397 if(!( PyArg_ParseTuple(args, "sO", &s, &obj) ))
399 Vec3f *v = Vec3f_ptr_from_PyObject(obj);
401 PyErr_SetString(PyExc_TypeError, "argument 2 must be a 3D vector (either a list of 3 elements or Vector)");
404 self->sa->setAttributeVec3f( s, *v );
410 ///////////////////////////////////////////////////////////////////////////////////////////