soc-2008-mxcurioni: implemented (without testing) StrokeShader, Stroke and MediumType...
[blender.git] / source / blender / freestyle / intern / python / StrokeShader.cpp
1 #include "StrokeShader.h"
2
3 #include "Convert.h"
4 #include "Interface1D/Stroke.h"
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 ///////////////////////////////////////////////////////////////////////////////////////////
11
12 /*---------------  Python API function prototypes for StrokeShader instance  -----------*/
13 static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds);
14 static void StrokeShader___dealloc__(BPy_StrokeShader *self);
15 static PyObject * StrokeShader___repr__(BPy_StrokeShader *self);
16
17 static PyObject * StrokeShader_getName( BPy_StrokeShader *self, PyObject *args);
18 static PyObject * StrokeShader_shade( BPy_StrokeShader *self , PyObject *args);
19
20 /*----------------------StrokeShader instance definitions ----------------------------*/
21 static PyMethodDef BPy_StrokeShader_methods[] = {
22         {"getName", ( PyCFunction ) StrokeShader_getName, METH_NOARGS, "( )Returns the string of the name of the binary predicate."},
23         {"shade", ( PyCFunction ) StrokeShader_shade, METH_VARARGS, "(Stroke s )The shading method. This method must be overloaded by inherited classes. The shading method is designed to modify any Stroke's attribute such as Thickness, Color, Geometry, Texture, Blending mode... The basic way to achieve this operation consists in iterating over the StrokeVertices of the Stroke and to modify each one's StrokeAttribute."},
24         {NULL, NULL, 0, NULL}
25 };
26
27 /*-----------------------BPy_StrokeShader type definition ------------------------------*/
28
29 PyTypeObject StrokeShader_Type = {
30         PyObject_HEAD_INIT( NULL ) 
31         0,                                                      /* ob_size */
32         "StrokeShader",                         /* tp_name */
33         sizeof( BPy_StrokeShader ),     /* tp_basicsize */
34         0,                                                      /* tp_itemsize */
35         
36         /* methods */
37         (destructor)StrokeShader___dealloc__,   /* tp_dealloc */
38         NULL,                                                   /* printfunc tp_print; */
39         NULL,                                                   /* getattrfunc tp_getattr; */
40         NULL,                                                   /* setattrfunc tp_setattr; */
41         NULL,                                                                           /* tp_compare */
42         (reprfunc)StrokeShader___repr__,                                        /* tp_repr */
43
44         /* Method suites for standard classes */
45
46         NULL,                       /* PyNumberMethods *tp_as_number; */
47         NULL,                       /* PySequenceMethods *tp_as_sequence; */
48         NULL,                       /* PyMappingMethods *tp_as_mapping; */
49
50         /* More standard operations (here for binary compatibility) */
51
52         NULL,                                           /* hashfunc tp_hash; */
53         NULL,                       /* ternaryfunc tp_call; */
54         NULL,                       /* reprfunc tp_str; */
55         NULL,                       /* getattrofunc tp_getattro; */
56         NULL,                       /* setattrofunc tp_setattro; */
57
58         /* Functions to access object as input/output buffer */
59         NULL,                       /* PyBufferProcs *tp_as_buffer; */
60
61   /*** Flags to define presence of optional/expanded features ***/
62         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* long tp_flags; */
63
64         NULL,                       /*  char *tp_doc;  Documentation string */
65   /*** Assigned meaning in release 2.0 ***/
66         /* call function for all accessible objects */
67         NULL,                       /* traverseproc tp_traverse; */
68
69         /* delete references to contained objects */
70         NULL,                       /* inquiry tp_clear; */
71
72   /***  Assigned meaning in release 2.1 ***/
73   /*** rich comparisons ***/
74         NULL,                       /* richcmpfunc tp_richcompare; */
75
76   /***  weak reference enabler ***/
77         0,                          /* long tp_weaklistoffset; */
78
79   /*** Added in release 2.2 ***/
80         /*   Iterators */
81         NULL,                       /* getiterfunc tp_iter; */
82         NULL,                       /* iternextfunc tp_iternext; */
83
84   /*** Attribute descriptor and subclassing stuff ***/
85         BPy_StrokeShader_methods,       /* struct PyMethodDef *tp_methods; */
86         NULL,                           /* struct PyMemberDef *tp_members; */
87         NULL,                                           /* struct PyGetSetDef *tp_getset; */
88         NULL,                                                   /* struct _typeobject *tp_base; */
89         NULL,                                                   /* PyObject *tp_dict; */
90         NULL,                                                   /* descrgetfunc tp_descr_get; */
91         NULL,                                                   /* descrsetfunc tp_descr_set; */
92         0,                              /* long tp_dictoffset; */
93         (initproc)StrokeShader___init__, /* initproc tp_init; */
94         NULL,                                                   /* allocfunc tp_alloc; */
95         PyType_GenericNew,              /* newfunc tp_new; */
96         
97         /*  Low-level free-memory routine */
98         NULL,                       /* freefunc tp_free;  */
99         
100         /* For PyObject_IS_GC */
101         NULL,                       /* inquiry tp_is_gc;  */
102         NULL,                       /* PyObject *tp_bases; */
103         
104         /* method resolution order */
105         NULL,                       /* PyObject *tp_mro;  */
106         NULL,                       /* PyObject *tp_cache; */
107         NULL,                       /* PyObject *tp_subclasses; */
108         NULL,                       /* PyObject *tp_weaklist; */
109         NULL
110 };
111
112 //-------------------MODULE INITIALIZATION--------------------------------
113 PyMODINIT_FUNC StrokeShader_Init( PyObject *module )
114 {
115         if( module == NULL )
116                 return;
117
118         if( PyType_Ready( &StrokeShader_Type ) < 0 )
119                 return;
120
121         Py_INCREF( &StrokeShader_Type );
122         PyModule_AddObject(module, "StrokeShader", (PyObject *)&StrokeShader_Type);
123 }
124
125 //------------------------INSTANCE METHODS ----------------------------------
126
127 int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
128 {
129         self->ss = new StrokeShader();
130         return 0;
131 }
132
133 void StrokeShader___dealloc__(BPy_StrokeShader* self)
134 {
135         delete self->ss;
136     self->ob_type->tp_free((PyObject*)self);
137 }
138
139
140 PyObject * StrokeShader___repr__(BPy_StrokeShader* self)
141 {
142     return PyString_FromFormat("type: %s - address: %p", self->ss->getName().c_str(), self->ss );
143 }
144
145
146 PyObject * StrokeShader_getName( BPy_StrokeShader *self, PyObject *args)
147 {
148         return PyString_FromString( self->ss->getName().c_str() );
149 }
150
151 PyObject *StrokeShader_shade( BPy_StrokeShader *self , PyObject *args) {
152         PyObject *py_s = 0;
153
154         if(!( PyArg_ParseTuple(args, "O", &py_s) && BPy_Stroke_Check(py_s) )) {
155                 cout << "ERROR: StrokeShader_shade" << endl;
156                 Py_RETURN_NONE;
157         }
158         
159         self->ss->shade(*( ((BPy_Stroke *) py_s)->s ));
160
161         Py_RETURN_NONE;
162 }
163
164
165
166 ///////////////////////////////////////////////////////////////////////////////////////////
167
168 #ifdef __cplusplus
169 }
170 #endif