Blender V4.5
BPy_ViewMap.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_ViewMap.h"
10
11#include "BPy_BBox.h"
12#include "BPy_Convert.h"
15
16using namespace Freestyle;
17
19
20//-------------------MODULE INITIALIZATION--------------------------------
21int ViewMap_Init(PyObject *module)
22{
23 if (module == nullptr) {
24 return -1;
25 }
26
27 if (PyType_Ready(&ViewMap_Type) < 0) {
28 return -1;
29 }
30 PyModule_AddObjectRef(module, "ViewMap", (PyObject *)&ViewMap_Type);
31
32 return 0;
33}
34
35/*----------------------ViewMap methods----------------------------*/
36
38 /* Wrap. */
39 ViewMap_doc,
40 "Class defining the ViewMap.\n"
41 "\n"
42 ".. method:: __init__()\n"
43 "\n"
44 " Default constructor.");
45
46static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
47{
48 static const char *kwlist[] = {nullptr};
49
50 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
51 return -1;
52 }
53 self->vm = new ViewMap();
54 return 0;
55}
56
58{
59 delete self->vm;
60 Py_TYPE(self)->tp_free((PyObject *)self);
61}
62
63static PyObject *ViewMap_repr(BPy_ViewMap *self)
64{
65 return PyUnicode_FromFormat("ViewMap - address: %p", self->vm);
66}
67
69 /* Wrap. */
70 ViewMap_get_closest_viewedge_doc,
71 ".. method:: get_closest_viewedge(x, y)\n"
72 "\n"
73 " Gets the ViewEdge nearest to the 2D point specified as arguments.\n"
74 "\n"
75 " :arg x: X coordinate of a 2D point.\n"
76 " :type x: float\n"
77 " :arg y: Y coordinate of a 2D point.\n"
78 " :type y: float\n"
79 " :return: The ViewEdge nearest to the specified 2D point.\n"
80 " :rtype: :class:`ViewEdge`");
81
82static PyObject *ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
83{
84 static const char *kwlist[] = {"x", "y", nullptr};
85 double x, y;
86
87 if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
88 return nullptr;
89 }
90 ViewEdge *ve = const_cast<ViewEdge *>(self->vm->getClosestViewEdge(x, y));
91 if (ve) {
93 }
94 Py_RETURN_NONE;
95}
96
98 /* Wrap. */
99 ViewMap_get_closest_fedge_doc,
100 ".. method:: get_closest_fedge(x, y)\n"
101 "\n"
102 " Gets the FEdge nearest to the 2D point specified as arguments.\n"
103 "\n"
104 " :arg x: X coordinate of a 2D point.\n"
105 " :type x: float\n"
106 " :arg y: Y coordinate of a 2D point.\n"
107 " :type y: float\n"
108 " :return: The FEdge nearest to the specified 2D point.\n"
109 " :rtype: :class:`FEdge`");
110
111static PyObject *ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
112{
113 static const char *kwlist[] = {"x", "y", nullptr};
114 double x, y;
115
116 if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
117 return nullptr;
118 }
119 FEdge *fe = const_cast<FEdge *>(self->vm->getClosestFEdge(x, y));
120 if (fe) {
121 return Any_BPy_FEdge_from_FEdge(*fe);
122 }
123 Py_RETURN_NONE;
124}
125
126// static ViewMap *getInstance ();
127
128#ifdef __GNUC__
129# ifdef __clang__
130# pragma clang diagnostic push
131# pragma clang diagnostic ignored "-Wcast-function-type"
132# else
133# pragma GCC diagnostic push
134# pragma GCC diagnostic ignored "-Wcast-function-type"
135# endif
136#endif
137
138static PyMethodDef BPy_ViewMap_methods[] = {
139 {"get_closest_viewedge",
140 (PyCFunction)ViewMap_get_closest_viewedge,
141 METH_VARARGS | METH_KEYWORDS,
142 ViewMap_get_closest_viewedge_doc},
143 {"get_closest_fedge",
144 (PyCFunction)ViewMap_get_closest_fedge,
145 METH_VARARGS | METH_KEYWORDS,
146 ViewMap_get_closest_fedge_doc},
147 {nullptr, nullptr, 0, nullptr},
148};
149
150#ifdef __GNUC__
151# ifdef __clang__
152# pragma clang diagnostic pop
153# else
154# pragma GCC diagnostic pop
155# endif
156#endif
157
158/*----------------------ViewMap get/setters ----------------------------*/
159
161 /* Wrap. */
162 ViewMap_scene_bbox_doc,
163 "The 3D bounding box of the scene.\n"
164 "\n"
165 ":type: :class:`BBox`");
166
167static PyObject *ViewMap_scene_bbox_get(BPy_ViewMap *self, void * /*closure*/)
168{
169 return BPy_BBox_from_BBox(self->vm->getScene3dBBox());
170}
171
172static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void * /*closure*/)
173{
174 if (!BPy_BBox_Check(value)) {
175 PyErr_SetString(PyExc_TypeError, "value must be a BBox");
176 return -1;
177 }
178 self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb));
179 return 0;
180}
181
182static PyGetSetDef BPy_ViewMap_getseters[] = {
183 {"scene_bbox",
186 ViewMap_scene_bbox_doc,
187 nullptr},
188 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
189};
190
191/*-----------------------BPy_ViewMap type definition ------------------------------*/
192
193PyTypeObject ViewMap_Type = {
194 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
195 /*tp_name*/ "ViewMap",
196 /*tp_basicsize*/ sizeof(BPy_ViewMap),
197 /*tp_itemsize*/ 0,
198 /*tp_dealloc*/ (destructor)ViewMap_dealloc,
199 /*tp_vectorcall_offset*/ 0,
200 /*tp_getattr*/ nullptr,
201 /*tp_setattr*/ nullptr,
202 /*tp_as_async*/ nullptr,
203 /*tp_repr*/ (reprfunc)ViewMap_repr,
204 /*tp_as_number*/ nullptr,
205 /*tp_as_sequence*/ nullptr,
206 /*tp_as_mapping*/ nullptr,
207 /*tp_hash*/ nullptr,
208 /*tp_call*/ nullptr,
209 /*tp_str*/ nullptr,
210 /*tp_getattro*/ nullptr,
211 /*tp_setattro*/ nullptr,
212 /*tp_as_buffer*/ nullptr,
213 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
214 /*tp_doc*/ ViewMap_doc,
215 /*tp_traverse*/ nullptr,
216 /*tp_clear*/ nullptr,
217 /*tp_richcompare*/ nullptr,
218 /*tp_weaklistoffset*/ 0,
219 /*tp_iter*/ nullptr,
220 /*tp_iternext*/ nullptr,
221 /*tp_methods*/ BPy_ViewMap_methods,
222 /*tp_members*/ nullptr,
223 /*tp_getset*/ BPy_ViewMap_getseters,
224 /*tp_base*/ nullptr,
225 /*tp_dict*/ nullptr,
226 /*tp_descr_get*/ nullptr,
227 /*tp_descr_set*/ nullptr,
228 /*tp_dictoffset*/ 0,
229 /*tp_init*/ (initproc)ViewMap_init,
230 /*tp_alloc*/ nullptr,
231 /*tp_new*/ PyType_GenericNew,
232};
233
#define BPy_BBox_Check(v)
Definition BPy_BBox.h:22
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * BPy_BBox_from_BBox(const BBox< Vec3r > &bb)
int ViewMap_Init(PyObject *module)
PyDoc_STRVAR(ViewMap_doc, "Class defining the ViewMap.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.")
static PyMethodDef BPy_ViewMap_methods[]
static PyObject * ViewMap_repr(BPy_ViewMap *self)
static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
static void ViewMap_dealloc(BPy_ViewMap *self)
static PyObject * ViewMap_scene_bbox_get(BPy_ViewMap *self, void *)
static PyGetSetDef BPy_ViewMap_getseters[]
static PyObject * ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
PyTypeObject ViewMap_Type
static PyObject * ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void *)
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796