Blender V5.0
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 "* Nature.POINT: True for any 0D element.\n"
74 "* Nature.S_VERTEX: True for SVertex.\n"
75 "* Nature.VIEW_VERTEX: True for ViewVertex.\n"
76 "* Nature.NON_T_VERTEX: True for NonTVertex.\n"
77 "* Nature.T_VERTEX: True for TVertex.\n"
78 "* Nature.CUSP: True for CUSP.\n"
79 "\n"
80 "Edge natures:\n"
81 "\n"
82 "* Nature.NO_FEATURE: True for non feature edges (always false for 1D\n"
83 " elements of the ViewMap).\n"
84 "* Nature.SILHOUETTE: True for silhouettes.\n"
85 "* Nature.BORDER: True for borders.\n"
86 "* Nature.CREASE: True for creases.\n"
87 "* Nature.RIDGE: True for ridges.\n"
88 "* Nature.VALLEY: True for valleys.\n"
89 "* Nature.SUGGESTIVE_CONTOUR: True for suggestive contours.\n"
90 "* Nature.MATERIAL_BOUNDARY: True for edges at material boundaries.\n"
91 "* Nature.EDGE_MARK: True for edges having user-defined edge marks.\n");
92PyTypeObject Nature_Type = {
93 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
94 /*tp_name*/ "Nature",
95 /*tp_basicsize*/ sizeof(PyLongObject),
96 /*tp_itemsize*/ 0,
97 /*tp_dealloc*/ nullptr,
98 /*tp_vectorcall_offset*/ 0,
99 /*tp_getattr*/ nullptr,
100 /*tp_setattr*/ nullptr,
101 /*tp_as_async*/ nullptr,
102 /*tp_repr*/ nullptr,
103 /*tp_as_number*/ &nature_as_number,
104 /*tp_as_sequence*/ nullptr,
105 /*tp_as_mapping*/ nullptr,
106 /*tp_hash*/ nullptr,
107 /*tp_call*/ nullptr,
108 /*tp_str*/ nullptr,
109 /*tp_getattro*/ nullptr,
110 /*tp_setattro*/ nullptr,
111 /*tp_as_buffer*/ nullptr,
112 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
113 /*tp_doc*/ Nature_doc,
114 /*tp_traverse*/ nullptr,
115 /*tp_clear*/ nullptr,
116 /*tp_richcompare*/ nullptr,
117 /*tp_weaklistoffset*/ 0,
118 /*tp_iter*/ nullptr,
119 /*tp_iternext*/ nullptr,
120 /*tp_methods*/ nullptr,
121 /*tp_members*/ nullptr,
122 /*tp_getset*/ nullptr,
123 /*tp_base*/ &PyLong_Type,
124 /*tp_dict*/ nullptr,
125 /*tp_descr_get*/ nullptr,
126 /*tp_descr_set*/ nullptr,
127 /*tp_dictoffset*/ 0,
128 /*tp_init*/ nullptr,
129 /*tp_alloc*/ nullptr,
130 /*tp_new*/ nullptr,
131};
132
133/*-----------------------BPy_Nature instance definitions ----------------------------------*/
134
135//-------------------MODULE INITIALIZATION--------------------------------
136int Nature_Init(PyObject *module)
137{
138 if (module == nullptr) {
139 return -1;
140 }
141
142 if (PyType_Ready(&Nature_Type) < 0) {
143 return -1;
144 }
145 PyModule_AddObjectRef(module, "Nature", (PyObject *)&Nature_Type);
146
147#define ADD_TYPE_CONST(id) \
148 PyLong_subtype_add_to_dict(Nature_Type.tp_dict, &Nature_Type, STRINGIFY(id), Nature::id)
149
150 // VertexNature
151 ADD_TYPE_CONST(POINT);
152 ADD_TYPE_CONST(S_VERTEX);
153 ADD_TYPE_CONST(VIEW_VERTEX);
154 ADD_TYPE_CONST(NON_T_VERTEX);
155 ADD_TYPE_CONST(T_VERTEX);
156 ADD_TYPE_CONST(CUSP);
157
158 // EdgeNature
159 ADD_TYPE_CONST(NO_FEATURE);
160 ADD_TYPE_CONST(SILHOUETTE);
161 ADD_TYPE_CONST(BORDER);
162 ADD_TYPE_CONST(CREASE);
163 ADD_TYPE_CONST(RIDGE);
164 ADD_TYPE_CONST(VALLEY);
165 ADD_TYPE_CONST(SUGGESTIVE_CONTOUR);
166 ADD_TYPE_CONST(MATERIAL_BOUNDARY);
168
169#undef ADD_TYPE_CONST
170
171 return 0;
172}
173
174static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
175{
177 long op1, op2, v;
178
180 PyErr_SetString(PyExc_TypeError, "operands must be a Nature object");
181 return nullptr;
182 }
183
184 if ((op1 = PyLong_AsLong(a)) == -1 && PyErr_Occurred()) {
185 PyErr_SetString(PyExc_ValueError, "operand 1: unexpected Nature value");
186 return nullptr;
187 }
188 if ((op2 = PyLong_AsLong(b)) == -1 && PyErr_Occurred()) {
189 PyErr_SetString(PyExc_ValueError, "operand 2: unexpected Nature value");
190 return nullptr;
191 }
192 switch (op) {
193 case '&':
194 v = op1 & op2;
195 break;
196 case '^':
197 v = op1 ^ op2;
198 break;
199 case '|':
200 v = op1 | op2;
201 break;
202 default:
203 PyErr_BadArgument();
204 return nullptr;
205 }
206 if (v == 0) {
207 result = PyObject_NewVar(BPy_Nature, &Nature_Type, 0);
208 }
209 else {
211 }
212 return (PyObject *)result;
213}
214
215static PyObject *BPy_Nature_and(PyObject *a, PyObject *b)
216{
217 return BPy_Nature_bitwise(a, '&', b);
218}
219
220static PyObject *BPy_Nature_xor(PyObject *a, PyObject *b)
221{
222 return BPy_Nature_bitwise(a, '^', b);
223}
224
225static PyObject *BPy_Nature_or(PyObject *a, PyObject *b)
226{
227 return BPy_Nature_bitwise(a, '|', b);
228}
229
PyObject * PyLong_subtype_new(PyTypeObject *ty, long value)
static PyObject * BPy_Nature_xor(PyObject *a, PyObject *b)
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.\n")
#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
static PyNumberMethods nature_as_number
static PyObject * BPy_Nature_and(PyObject *a, PyObject *b)
#define BPy_Nature_Check(v)
Definition BPy_Nature.h:21
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define EDGE_MARK
Definition bmo_bridge.cc:26
inherits from class Rep
Definition AppCanvas.cpp:20
static uint a[3]
Definition RandGen.cpp:82
static struct PyModuleDef module
Definition python.cpp:796