Blender V5.3
BPy_Nature.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_Nature.h"
10
11#include "BPy_Convert.h"
12
13using namespace Freestyle;
14
16
17static PyObject *BPy_Nature_and(PyObject *a, PyObject *b);
18static PyObject *BPy_Nature_xor(PyObject *a, PyObject *b);
19static PyObject *BPy_Nature_or(PyObject *a, PyObject *b);
20
21/*-----------------------BPy_Nature number method definitions --------------------*/
22
23static PyNumberMethods nature_as_number = {
24 /*nb_add*/ nullptr,
25 /*nb_subtract*/ nullptr,
26 /*nb_multiply*/ nullptr,
27 /*nb_remainder*/ nullptr,
28 /*nb_divmod*/ nullptr,
29 /*nb_power*/ nullptr,
30 /*nb_negative*/ nullptr,
31 /*nb_positive*/ nullptr,
32 /*nb_absolute*/ nullptr,
33 /*nb_bool*/ nullptr,
34 /*nb_invert*/ nullptr,
35 /*nb_lshift*/ nullptr,
36 /*nb_rshift*/ nullptr,
37 /*nb_and*/ (binaryfunc)BPy_Nature_and,
38 /*nb_xor*/ (binaryfunc)BPy_Nature_xor,
39 /*nb_or*/ (binaryfunc)BPy_Nature_or,
40 /*nb_int*/ nullptr,
41 /*nb_reserved*/ nullptr,
42 /*nb_float*/ nullptr,
43 /*nb_inplace_add*/ nullptr,
44 /*nb_inplace_subtract*/ nullptr,
45 /*nb_inplace_multiply*/ nullptr,
46 /*nb_inplace_remainder*/ nullptr,
47 /*nb_inplace_power*/ nullptr,
48 /*nb_inplace_lshift*/ nullptr,
49 /*nb_inplace_rshift*/ nullptr,
50 /*nb_inplace_and*/ nullptr,
51 /*nb_inplace_xor*/ nullptr,
52 /*nb_inplace_or*/ nullptr,
53 /*nb_floor_divide*/ nullptr,
54 /*nb_true_divide*/ nullptr,
55 /*nb_inplace_floor_divide*/ nullptr,
56 /*nb_inplace_true_divide*/ nullptr,
57 /*nb_index*/ nullptr,
58 /*nb_matrix_multiply*/ nullptr,
59 /*nb_inplace_matrix_multiply*/ nullptr,
60};
61
62/*-----------------------BPy_Nature type definition ------------------------------*/
63
65 /* Wrap. */
66 Nature_doc,
67 "Class hierarchy: int > :class:`Nature`\n"
68 "\n"
69 "Different possible natures of 0D and 1D elements of the ViewMap.\n"
70 "\n"
71 "Vertex natures:\n"
72 "\n"
73 ".. attribute:: POINT\n"
74 "\n"
75 " True for any 0D element.\n"
76 "\n"
77 ".. attribute:: S_VERTEX\n"
78 "\n"
79 " True for SVertex.\n"
80 "\n"
81 ".. attribute:: VIEW_VERTEX\n"
82 "\n"
83 " True for ViewVertex.\n"
84 "\n"
85 ".. attribute:: NON_T_VERTEX\n"
86 "\n"
87 " True for NonTVertex.\n"
88 "\n"
89 ".. attribute:: T_VERTEX\n"
90 "\n"
91 " True for TVertex.\n"
92 "\n"
93 ".. attribute:: CUSP\n"
94 "\n"
95 " True for CUSP.\n"
96 "\n"
97 "Edge natures:\n"
98 "\n"
99 ".. attribute:: NO_FEATURE\n"
100 "\n"
101 " True for non feature edges (always false for 1D elements of the ViewMap).\n"
102 "\n"
103 ".. attribute:: SILHOUETTE\n"
104 "\n"
105 " True for silhouettes.\n"
106 "\n"
107 ".. attribute:: BORDER\n"
108 "\n"
109 " True for borders.\n"
110 "\n"
111 ".. attribute:: CREASE\n"
112 "\n"
113 " True for creases.\n"
114 "\n"
115 ".. attribute:: RIDGE\n"
116 "\n"
117 " True for ridges.\n"
118 "\n"
119 ".. attribute:: VALLEY\n"
120 "\n"
121 " True for valleys.\n"
122 "\n"
123 ".. attribute:: SUGGESTIVE_CONTOUR\n"
124 "\n"
125 " True for suggestive contours.\n"
126 "\n"
127 ".. attribute:: MATERIAL_BOUNDARY\n"
128 "\n"
129 " True for edges at material boundaries.\n"
130 "\n"
131 ".. attribute:: EDGE_MARK\n"
132 "\n"
133 " True for edges having user-defined edge marks.\n");
134PyTypeObject Nature_Type = {
135 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
136 /*tp_name*/ "Nature",
137 /*tp_basicsize*/ sizeof(PyLongObject),
138 /*tp_itemsize*/ 0,
139 /*tp_dealloc*/ nullptr,
140 /*tp_vectorcall_offset*/ 0,
141 /*tp_getattr*/ nullptr,
142 /*tp_setattr*/ nullptr,
143 /*tp_as_async*/ nullptr,
144 /*tp_repr*/ nullptr,
145 /*tp_as_number*/ &nature_as_number,
146 /*tp_as_sequence*/ nullptr,
147 /*tp_as_mapping*/ nullptr,
148 /*tp_hash*/ nullptr,
149 /*tp_call*/ nullptr,
150 /*tp_str*/ nullptr,
151 /*tp_getattro*/ nullptr,
152 /*tp_setattro*/ nullptr,
153 /*tp_as_buffer*/ nullptr,
154 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
155 /*tp_doc*/ Nature_doc,
156 /*tp_traverse*/ nullptr,
157 /*tp_clear*/ nullptr,
158 /*tp_richcompare*/ nullptr,
159 /*tp_weaklistoffset*/ 0,
160 /*tp_iter*/ nullptr,
161 /*tp_iternext*/ nullptr,
162 /*tp_methods*/ nullptr,
163 /*tp_members*/ nullptr,
164 /*tp_getset*/ nullptr,
165 /*tp_base*/ &PyLong_Type,
166 /*tp_dict*/ nullptr,
167 /*tp_descr_get*/ nullptr,
168 /*tp_descr_set*/ nullptr,
169 /*tp_dictoffset*/ 0,
170 /*tp_init*/ nullptr,
171 /*tp_alloc*/ nullptr,
172 /*tp_new*/ nullptr,
173};
174
175/*-----------------------BPy_Nature instance definitions ----------------------------------*/
176
177//-------------------MODULE INITIALIZATION--------------------------------
178int Nature_Init(PyObject *module)
179{
180 if (module == nullptr) {
181 return -1;
182 }
183
184 if (PyType_Ready(&Nature_Type) < 0) {
185 return -1;
186 }
187 PyModule_AddObjectRef(module, "Nature", (PyObject *)&Nature_Type);
188
189#define ADD_TYPE_CONST(id) \
190 PyLong_subtype_add_to_dict(Nature_Type.tp_dict, &Nature_Type, STRINGIFY(id), Nature::id)
191
192 // VertexNature
193 ADD_TYPE_CONST(POINT);
194 ADD_TYPE_CONST(S_VERTEX);
195 ADD_TYPE_CONST(VIEW_VERTEX);
196 ADD_TYPE_CONST(NON_T_VERTEX);
197 ADD_TYPE_CONST(T_VERTEX);
198 ADD_TYPE_CONST(CUSP);
199
200 // EdgeNature
201 ADD_TYPE_CONST(NO_FEATURE);
202 ADD_TYPE_CONST(SILHOUETTE);
203 ADD_TYPE_CONST(BORDER);
204 ADD_TYPE_CONST(CREASE);
205 ADD_TYPE_CONST(RIDGE);
206 ADD_TYPE_CONST(VALLEY);
207 ADD_TYPE_CONST(SUGGESTIVE_CONTOUR);
208 ADD_TYPE_CONST(MATERIAL_BOUNDARY);
210
211#undef ADD_TYPE_CONST
212
213 return 0;
214}
215
216static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
217{
218 long op1, op2, v;
219
220 if (!BPy_Nature_Check(a) || !BPy_Nature_Check(b)) {
221 PyErr_SetString(PyExc_TypeError, "operands must be a Nature object");
222 return nullptr;
223 }
224
225 if ((op1 = PyLong_AsLong(a)) == -1 && PyErr_Occurred()) {
226 PyErr_SetString(PyExc_ValueError, "operand 1: unexpected Nature value");
227 return nullptr;
228 }
229 if ((op2 = PyLong_AsLong(b)) == -1 && PyErr_Occurred()) {
230 PyErr_SetString(PyExc_ValueError, "operand 2: unexpected Nature value");
231 return nullptr;
232 }
233 switch (op) {
234 case '&':
235 v = op1 & op2;
236 break;
237 case '^':
238 v = op1 ^ op2;
239 break;
240 case '|':
241 v = op1 | op2;
242 break;
243 default:
244 PyErr_BadArgument();
245 return nullptr;
246 }
248}
249
250static PyObject *BPy_Nature_and(PyObject *a, PyObject *b)
251{
252 return BPy_Nature_bitwise(a, '&', b);
253}
254
255static PyObject *BPy_Nature_xor(PyObject *a, PyObject *b)
256{
257 return BPy_Nature_bitwise(a, '^', b);
258}
259
260static PyObject *BPy_Nature_or(PyObject *a, PyObject *b)
261{
262 return BPy_Nature_bitwise(a, '|', b);
263}
264
PyObject * PyLong_subtype_new(PyTypeObject *ty, long value)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
#define ADD_TYPE_CONST(id)
static PyObject * BPy_Nature_xor(PyObject *a, PyObject *b)
static PyObject * BPy_Nature_or(PyObject *a, PyObject *b)
int Nature_Init(PyObject *module)
static PyObject * BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
PyTypeObject Nature_Type
static PyNumberMethods nature_as_number
static PyObject * BPy_Nature_and(PyObject *a, PyObject *b)
#define BPy_Nature_Check(v)
Definition BPy_Nature.h:21
#define EDGE_MARK
Definition bmo_bridge.cc:28
inherits from class Rep
Definition AppCanvas.cpp:20