Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BPy_FEdge.cpp « Interface1D « python « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9684f96d586d7cfbf08ed83e9855471857cdb765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup freestyle
 */

#include "BPy_FEdge.h"

#include "../BPy_Convert.h"
#include "../BPy_Id.h"
#include "../BPy_Nature.h"
#include "../Interface0D/BPy_SVertex.h"
#include "../Interface1D/BPy_ViewEdge.h"

#ifdef __cplusplus
extern "C" {
#endif

using namespace Freestyle;

///////////////////////////////////////////////////////////////////////////////////////////

/*----------------------FEdge methods ----------------------------*/

PyDoc_STRVAR(FEdge_doc,
             "Class hierarchy: :class:`Interface1D` > :class:`FEdge`\n"
             "\n"
             "Base Class for feature edges.  This FEdge can represent a silhouette,\n"
             "a crease, a ridge/valley, a border or a suggestive contour.  For\n"
             "silhouettes, the FEdge is oriented so that the visible face lies on\n"
             "the left of the edge.  For borders, the FEdge is oriented so that the\n"
             "face lies on the left of the edge.  An FEdge can represent an initial\n"
             "edge of the mesh or runs across a face of the initial mesh depending\n"
             "on the smoothness or sharpness of the mesh.  This class is specialized\n"
             "into a smooth and a sharp version since their properties slightly vary\n"
             "from one to the other.\n"
             "\n"
             ".. method:: FEdge()\n"
             "            FEdge(brother)\n"
             "\n"
             "   Builds an :class:`FEdge` using the default constructor,\n"
             "   copy constructor, or between two :class:`SVertex` objects.\n"
             "\n"
             "   :arg brother: An FEdge object.\n"
             "   :type brother: :class:`FEdge`\n"
             "   :arg first_vertex: The first SVertex.\n"
             "   :type first_vertex: :class:`SVertex`\n"
             "   :arg second_vertex: The second SVertex.\n"
             "   :type second_vertex: :class:`SVertex`");

static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds)
{
  static const char *kwlist_1[] = {"brother", nullptr};
  static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
  PyObject *obj1 = nullptr, *obj2 = nullptr;

  if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdge_Type, &obj1)) {
    if (!obj1) {
      self->fe = new FEdge();
    }
    else {
      self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe));
    }
  }
  else if ((void)PyErr_Clear(),
           PyArg_ParseTupleAndKeywords(args,
                                       kwds,
                                       "O!O!",
                                       (char **)kwlist_2,
                                       &SVertex_Type,
                                       &obj1,
                                       &SVertex_Type,
                                       &obj2)) {
    self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
  }
  else {
    PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
    return -1;
  }
  self->py_if1D.if1D = self->fe;
  self->py_if1D.borrowed = false;
  return 0;
}

/*----------------------FEdge sequence protocol ----------------------------*/

static Py_ssize_t FEdge_sq_length(BPy_FEdge * /*self*/)
{
  return 2;
}

static PyObject *FEdge_sq_item(BPy_FEdge *self, Py_ssize_t keynum)
{
  if (keynum < 0) {
    keynum += FEdge_sq_length(self);
  }
  if (ELEM(keynum, 0, 1)) {
    SVertex *v = self->fe->operator[](keynum);
    if (v) {
      return BPy_SVertex_from_SVertex(*v);
    }
    Py_RETURN_NONE;
  }
  PyErr_Format(PyExc_IndexError, "FEdge[index]: index %d out of range", keynum);
  return nullptr;
}

static PySequenceMethods BPy_FEdge_as_sequence = {
    /*sq_length*/ (lenfunc)FEdge_sq_length,
    /*sq_concat*/ nullptr,
    /*sq_repeat*/ nullptr,
    /*sq_item*/ (ssizeargfunc)FEdge_sq_item,
    /*was_sq_slice*/ nullptr, /* DEPRECATED. */
    /*sq_ass_item*/ nullptr,
    /*was_sq_ass_slice*/ nullptr, /* DEPRECATED. */
    /*sq_contains*/ nullptr,
    /*sq_inplace_concat*/ nullptr,
    /*sq_inplace_repeat*/ nullptr,
};

/*----------------------FEdge get/setters ----------------------------*/

PyDoc_STRVAR(FEdge_first_svertex_doc,
             "The first SVertex constituting this FEdge.\n"
             "\n"
             ":type: :class:`SVertex`");

static PyObject *FEdge_first_svertex_get(BPy_FEdge *self, void * /*closure*/)
{
  SVertex *A = self->fe->vertexA();
  if (A) {
    return BPy_SVertex_from_SVertex(*A);
  }
  Py_RETURN_NONE;
}

static int FEdge_first_svertex_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_SVertex_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
    return -1;
  }
  self->fe->setVertexA(((BPy_SVertex *)value)->sv);
  return 0;
}

PyDoc_STRVAR(FEdge_second_svertex_doc,
             "The second SVertex constituting this FEdge.\n"
             "\n"
             ":type: :class:`SVertex`");

static PyObject *FEdge_second_svertex_get(BPy_FEdge *self, void * /*closure*/)
{
  SVertex *B = self->fe->vertexB();
  if (B) {
    return BPy_SVertex_from_SVertex(*B);
  }
  Py_RETURN_NONE;
}

static int FEdge_second_svertex_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_SVertex_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
    return -1;
  }
  self->fe->setVertexB(((BPy_SVertex *)value)->sv);
  return 0;
}

PyDoc_STRVAR(FEdge_next_fedge_doc,
             "The FEdge following this one in the ViewEdge.  The value is None if\n"
             "this FEdge is the last of the ViewEdge.\n"
             "\n"
             ":type: :class:`FEdge`");

static PyObject *FEdge_next_fedge_get(BPy_FEdge *self, void * /*closure*/)
{
  FEdge *fe = self->fe->nextEdge();
  if (fe) {
    return Any_BPy_FEdge_from_FEdge(*fe);
  }
  Py_RETURN_NONE;
}

static int FEdge_next_fedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_FEdge_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an FEdge");
    return -1;
  }
  self->fe->setNextEdge(((BPy_FEdge *)value)->fe);
  return 0;
}

PyDoc_STRVAR(FEdge_previous_fedge_doc,
             "The FEdge preceding this one in the ViewEdge.  The value is None if\n"
             "this FEdge is the first one of the ViewEdge.\n"
             "\n"
             ":type: :class:`FEdge`");

static PyObject *FEdge_previous_fedge_get(BPy_FEdge *self, void * /*closure*/)
{
  FEdge *fe = self->fe->previousEdge();
  if (fe) {
    return Any_BPy_FEdge_from_FEdge(*fe);
  }
  Py_RETURN_NONE;
}

static int FEdge_previous_fedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_FEdge_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an FEdge");
    return -1;
  }
  self->fe->setPreviousEdge(((BPy_FEdge *)value)->fe);
  return 0;
}

PyDoc_STRVAR(FEdge_viewedge_doc,
             "The ViewEdge to which this FEdge belongs to.\n"
             "\n"
             ":type: :class:`ViewEdge`");

static PyObject *FEdge_viewedge_get(BPy_FEdge *self, void * /*closure*/)
{
  ViewEdge *ve = self->fe->viewedge();
  if (ve) {
    return BPy_ViewEdge_from_ViewEdge(*ve);
  }
  Py_RETURN_NONE;
}

static int FEdge_viewedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_ViewEdge_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an ViewEdge");
    return -1;
  }
  self->fe->setViewEdge(((BPy_ViewEdge *)value)->ve);
  return 0;
}

PyDoc_STRVAR(FEdge_is_smooth_doc,
             "True if this FEdge is a smooth FEdge.\n"
             "\n"
             ":type: bool");

static PyObject *FEdge_is_smooth_get(BPy_FEdge *self, void * /*closure*/)
{
  return PyBool_from_bool(self->fe->isSmooth());
}

static int FEdge_is_smooth_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!PyBool_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be boolean");
    return -1;
  }
  self->fe->setSmooth(bool_from_PyBool(value));
  return 0;
}

PyDoc_STRVAR(FEdge_id_doc,
             "The Id of this FEdge.\n"
             "\n"
             ":type: :class:`Id`");

static PyObject *FEdge_id_get(BPy_FEdge *self, void * /*closure*/)
{
  Id id(self->fe->getId());
  return BPy_Id_from_Id(id);  // return a copy
}

static int FEdge_id_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_Id_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be an Id");
    return -1;
  }
  self->fe->setId(*(((BPy_Id *)value)->id));
  return 0;
}

PyDoc_STRVAR(FEdge_nature_doc,
             "The nature of this FEdge.\n"
             "\n"
             ":type: :class:`Nature`");

static PyObject *FEdge_nature_get(BPy_FEdge *self, void * /*closure*/)
{
  return BPy_Nature_from_Nature(self->fe->getNature());
}

static int FEdge_nature_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
{
  if (!BPy_Nature_Check(value)) {
    PyErr_SetString(PyExc_TypeError, "value must be a Nature");
    return -1;
  }
  self->fe->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i));
  return 0;
}

static PyGetSetDef BPy_FEdge_getseters[] = {
    {"first_svertex",
     (getter)FEdge_first_svertex_get,
     (setter)FEdge_first_svertex_set,
     FEdge_first_svertex_doc,
     nullptr},
    {"second_svertex",
     (getter)FEdge_second_svertex_get,
     (setter)FEdge_second_svertex_set,
     FEdge_second_svertex_doc,
     nullptr},
    {"next_fedge",
     (getter)FEdge_next_fedge_get,
     (setter)FEdge_next_fedge_set,
     FEdge_next_fedge_doc,
     nullptr},
    {"previous_fedge",
     (getter)FEdge_previous_fedge_get,
     (setter)FEdge_previous_fedge_set,
     FEdge_previous_fedge_doc,
     nullptr},
    {"viewedge",
     (getter)FEdge_viewedge_get,
     (setter)FEdge_viewedge_set,
     FEdge_viewedge_doc,
     nullptr},
    {"is_smooth",
     (getter)FEdge_is_smooth_get,
     (setter)FEdge_is_smooth_set,
     FEdge_is_smooth_doc,
     nullptr},
    {"id", (getter)FEdge_id_get, (setter)FEdge_id_set, FEdge_id_doc, nullptr},
    {"nature", (getter)FEdge_nature_get, (setter)FEdge_nature_set, FEdge_nature_doc, nullptr},
    {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};

/*-----------------------BPy_FEdge type definition ------------------------------*/

PyTypeObject FEdge_Type = {
    PyVarObject_HEAD_INIT(nullptr, 0)
    /*tp_name*/ "FEdge",
    /*tp_basicsize*/ sizeof(BPy_FEdge),
    /*tp_itemsize*/ 0,
    /*tp_dealloc*/ nullptr,
    /*tp_vectorcall_offset*/ 0,
    /*tp_getattr*/ nullptr,
    /*tp_setattr*/ nullptr,
    /*tp_as_async*/ nullptr,
    /*tp_repr*/ nullptr,
    /*tp_as_number*/ nullptr,
    /*tp_as_sequence*/ &BPy_FEdge_as_sequence,
    /*tp_as_mapping*/ nullptr,
    /*tp_hash*/ nullptr,
    /*tp_call*/ nullptr,
    /*tp_str*/ nullptr,
    /*tp_getattro*/ nullptr,
    /*tp_setattro*/ nullptr,
    /*tp_as_buffer*/ nullptr,
    /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
    /*tp_doc*/ FEdge_doc,
    /*tp_traverse*/ nullptr,
    /*tp_clear*/ nullptr,
    /*tp_richcompare*/ nullptr,
    /*tp_weaklistoffset*/ 0,
    /*tp_iter*/ nullptr,
    /*tp_iternext*/ nullptr,
    /*tp_methods*/ nullptr,
    /*tp_members*/ nullptr,
    /*tp_getset*/ BPy_FEdge_getseters,
    /*tp_base*/ &Interface1D_Type,
    /*tp_dict*/ nullptr,
    /*tp_descr_get*/ nullptr,
    /*tp_descr_set*/ nullptr,
    /*tp_dictoffset*/ 0,
    /*tp_init*/ (initproc)FEdge_init,
    /*tp_alloc*/ nullptr,
    /*tp_new*/ nullptr,
};

///////////////////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
}
#endif