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