1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16
17 /** \file
18 * \ingroup freestyle
19 */
20
21 #include "BPy_NonTVertex.h"
22
23 #include "../../BPy_Convert.h"
24 #include "../BPy_SVertex.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 ///////////////////////////////////////////////////////////////////////////////////////////
31
32 /*----------------------NonTVertex methods ----------------------------*/
33
34 PyDoc_STRVAR(
35 NonTVertex_doc,
36 "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`NonTVertex`\n"
37 "\n"
38 "View vertex for corners, cusps, etc. associated to a single SVertex.\n"
39 "Can be associated to 2 or more view edges.\n"
40 "\n"
41 ".. method:: __init__()\n"
42 " __init__(svertex)\n"
43 "\n"
44 " Builds a :class:`NonTVertex` using the default constructor or a :class:`SVertex`.\n"
45 "\n"
46 " :arg svertex: An SVertex object.\n"
47 " :type svertex: :class:`SVertex`");
48
49 /* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */
50
NonTVertex_init(BPy_NonTVertex * self,PyObject * args,PyObject * kwds)51 static int NonTVertex_init(BPy_NonTVertex *self, PyObject *args, PyObject *kwds)
52 {
53 static const char *kwlist[] = {"svertex", NULL};
54 PyObject *obj = 0;
55
56 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SVertex_Type, &obj)) {
57 return -1;
58 }
59 if (!obj) {
60 self->ntv = new NonTVertex();
61 }
62 else {
63 self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv);
64 }
65 self->py_vv.vv = self->ntv;
66 self->py_vv.py_if0D.if0D = self->ntv;
67 self->py_vv.py_if0D.borrowed = false;
68 return 0;
69 }
70
71 /*----------------------NonTVertex get/setters ----------------------------*/
72
73 PyDoc_STRVAR(NonTVertex_svertex_doc,
74 "The SVertex on top of which this NonTVertex is built.\n"
75 "\n"
76 ":type: :class:`SVertex`");
77
NonTVertex_svertex_get(BPy_NonTVertex * self,void * UNUSED (closure))78 static PyObject *NonTVertex_svertex_get(BPy_NonTVertex *self, void *UNUSED(closure))
79 {
80 SVertex *v = self->ntv->svertex();
81 if (v) {
82 return BPy_SVertex_from_SVertex(*v);
83 }
84 Py_RETURN_NONE;
85 }
86
NonTVertex_svertex_set(BPy_NonTVertex * self,PyObject * value,void * UNUSED (closure))87 static int NonTVertex_svertex_set(BPy_NonTVertex *self, PyObject *value, void *UNUSED(closure))
88 {
89 if (!BPy_SVertex_Check(value)) {
90 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
91 return -1;
92 }
93 self->ntv->setSVertex(((BPy_SVertex *)value)->sv);
94 return 0;
95 }
96
97 static PyGetSetDef BPy_NonTVertex_getseters[] = {
98 {"svertex",
99 (getter)NonTVertex_svertex_get,
100 (setter)NonTVertex_svertex_set,
101 NonTVertex_svertex_doc,
102 NULL},
103 {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
104 };
105
106 /*-----------------------BPy_NonTVertex type definition ------------------------------*/
107 PyTypeObject NonTVertex_Type = {
108 PyVarObject_HEAD_INIT(NULL, 0) "NonTVertex", /* tp_name */
109 sizeof(BPy_NonTVertex), /* tp_basicsize */
110 0, /* tp_itemsize */
111 0, /* tp_dealloc */
112 0, /* tp_print */
113 0, /* tp_getattr */
114 0, /* tp_setattr */
115 0, /* tp_reserved */
116 0, /* tp_repr */
117 0, /* tp_as_number */
118 0, /* tp_as_sequence */
119 0, /* tp_as_mapping */
120 0, /* tp_hash */
121 0, /* tp_call */
122 0, /* tp_str */
123 0, /* tp_getattro */
124 0, /* tp_setattro */
125 0, /* tp_as_buffer */
126 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
127 NonTVertex_doc, /* tp_doc */
128 0, /* tp_traverse */
129 0, /* tp_clear */
130 0, /* tp_richcompare */
131 0, /* tp_weaklistoffset */
132 0, /* tp_iter */
133 0, /* tp_iternext */
134 0, /* tp_methods */
135 0, /* tp_members */
136 BPy_NonTVertex_getseters, /* tp_getset */
137 &ViewVertex_Type, /* tp_base */
138 0, /* tp_dict */
139 0, /* tp_descr_get */
140 0, /* tp_descr_set */
141 0, /* tp_dictoffset */
142 (initproc)NonTVertex_init, /* tp_init */
143 0, /* tp_alloc */
144 0, /* tp_new */
145 };
146
147 ///////////////////////////////////////////////////////////////////////////////////////////
148
149 #ifdef __cplusplus
150 }
151 #endif
152