c85134f71d53df3f97503ede2c8f326764029503
[blender.git] / source / blender / freestyle / intern / python / Interface1D / Curve / BPy_Chain.cpp
1 #include "BPy_Chain.h"
2
3 #include "../../BPy_Convert.h"
4 #include "../../BPy_Id.h"
5 #include "../BPy_ViewEdge.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 ///////////////////////////////////////////////////////////////////////////////////////////
12
13 //------------------------INSTANCE METHODS ----------------------------------
14
15 static char Chain___doc__[] =
16 "Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n"
17 "\n"
18 "Class to represent a 1D elements issued from the chaining process.  A\n"
19 "Chain is the last step before the :class:`Stroke` and is used in the\n"
20 "Splitting and Creation processes.\n"
21 "\n"
22 ".. method:: __init__()\n"
23 "\n"
24 "   Defult constructor.\n"
25 "\n"
26 ".. method:: __init__(iBrother)\n"
27 "\n"
28 "   Copy constructor.\n"
29 "\n"
30 "   :arg iBrother: A Chain object.\n"
31 "   :type iBrother: :class:`Chain`\n"
32 "\n"
33 ".. method:: __init__(id)\n"
34 "\n"
35 "   Builds a chain from its Id.\n"
36 "\n"
37 "   :arg id: An Id object.\n"
38 "   :type id: :class:`Id`\n";
39
40 int Chain___init__(BPy_Chain *self, PyObject *args, PyObject *kwds)
41 {
42
43         PyObject *obj = 0;
44
45     if (! PyArg_ParseTuple(args, "|O", &obj) )
46         return -1;
47
48         if( !obj ){
49                 self->c = new Chain();
50                 
51         } else if( BPy_Chain_Check(obj) ) {
52                 self->c = new Chain(*( ((BPy_Chain *) obj)->c ));
53                 
54         } else if( BPy_Id_Check(obj) ) {
55                 self->c = new Chain(*( ((BPy_Id *) obj)->id ));
56                         
57         } else {
58                 PyErr_SetString(PyExc_TypeError, "invalid argument");
59                 return -1;
60         }
61
62         self->py_c.c = self->c;
63         self->py_c.py_if1D.if1D = self->c;
64         self->py_c.py_if1D.borrowed = 0;
65
66         return 0;
67 }
68
69 static char Chain_push_viewedge_back___doc__[] =
70 ".. method:: push_viewedge_back(iViewEdge, orientation)\n"
71 "\n"
72 "   Adds a ViewEdge at the end of the Chain.\n"
73 "\n"
74 "   :arg iViewEdge: The ViewEdge that must be added.\n"
75 "   :type iViewEdge: :class:`ViewEdge`\n"
76 "   :arg orientation: The orientation with which the ViewEdge must be\n"
77 "      processed.\n"
78 "   :type orientation: bool\n";
79
80 PyObject * Chain_push_viewedge_back( BPy_Chain *self, PyObject *args ) {
81         PyObject *obj1 = 0, *obj2 = 0;
82
83         if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) ))
84                 return NULL;
85
86         ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve;
87         bool orientation = bool_from_PyBool( obj2 );
88         self->c->push_viewedge_back( ve, orientation);
89
90         Py_RETURN_NONE;
91 }
92
93 static char Chain_push_viewedge_front___doc__[] =
94 ".. method:: push_viewedge_front(iViewEdge, orientation)\n"
95 "\n"
96 "   Adds a ViewEdge at the beginning of the Chain.\n"
97 "\n"
98 "   :arg iViewEdge: The ViewEdge that must be added.\n"
99 "   :type iViewEdge: :class:`ViewEdge`\n"
100 "   :arg orientation: The orientation with which the ViewEdge must be\n"
101 "      processed.\n"
102 "   :type orientation: bool\n";
103
104 PyObject * Chain_push_viewedge_front( BPy_Chain *self, PyObject *args ) {
105         PyObject *obj1 = 0, *obj2 = 0;
106
107         if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) ))
108                 return NULL;
109
110         ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve;
111         bool orientation = bool_from_PyBool( obj2 );
112         self->c->push_viewedge_front(ve, orientation);
113
114         Py_RETURN_NONE;
115 }
116
117 /*----------------------Chain instance definitions ----------------------------*/
118 static PyMethodDef BPy_Chain_methods[] = {      
119         {"push_viewedge_back", ( PyCFunction ) Chain_push_viewedge_back, METH_VARARGS, Chain_push_viewedge_back___doc__},
120         {"push_viewedge_front", ( PyCFunction ) Chain_push_viewedge_front, METH_VARARGS, Chain_push_viewedge_front___doc__},
121         {NULL, NULL, 0, NULL}
122 };
123
124 /*-----------------------BPy_Chain type definition ------------------------------*/
125
126 PyTypeObject Chain_Type = {
127         PyVarObject_HEAD_INIT(NULL, 0)
128         "Chain",                        /* tp_name */
129         sizeof(BPy_Chain),              /* 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         Chain___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_Chain_methods,              /* tp_methods */
155         0,                              /* tp_members */
156         0,                              /* tp_getset */
157         &FrsCurve_Type,                 /* tp_base */
158         0,                              /* tp_dict */
159         0,                              /* tp_descr_get */
160         0,                              /* tp_descr_set */
161         0,                              /* tp_dictoffset */
162         (initproc)Chain___init__,       /* tp_init */
163         0,                              /* tp_alloc */
164         0,                              /* tp_new */
165 };
166
167 ///////////////////////////////////////////////////////////////////////////////////////////
168
169 #ifdef __cplusplus
170 }
171 #endif