Blender V5.0
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.\n");
45static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
46{
47 static const char *kwlist[] = {nullptr};
48
49 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
50 return -1;
51 }
52 self->vm = new ViewMap();
53 return 0;
54}
55
57{
58 delete self->vm;
59 Py_TYPE(self)->tp_free((PyObject *)self);
60}
61
62static PyObject *ViewMap_repr(BPy_ViewMap *self)
63{
64 return PyUnicode_FromFormat("ViewMap - address: %p", self->vm);
65}
66
68 /* Wrap. */
69 ViewMap_get_closest_viewedge_doc,
70 ".. method:: get_closest_viewedge(x, y)\n"
71 "\n"
72 " Gets the ViewEdge nearest to the 2D point specified as arguments.\n"
73 "\n"
74 " :arg x: X coordinate of a 2D point.\n"
75 " :type x: float\n"
76 " :arg y: Y coordinate of a 2D point.\n"
77 " :type y: float\n"
78 " :return: The ViewEdge nearest to the specified 2D point.\n"
79 " :rtype: :class:`ViewEdge`\n");
80static PyObject *ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
81{
82 static const char *kwlist[] = {"x", "y", nullptr};
83 double x, y;
84
85 if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
86 return nullptr;
87 }
88 ViewEdge *ve = const_cast<ViewEdge *>(self->vm->getClosestViewEdge(x, y));
89 if (ve) {
91 }
92 Py_RETURN_NONE;
93}
94
96 /* Wrap. */
97 ViewMap_get_closest_fedge_doc,
98 ".. method:: get_closest_fedge(x, y)\n"
99 "\n"
100 " Gets the FEdge nearest to the 2D point specified as arguments.\n"
101 "\n"
102 " :arg x: X coordinate of a 2D point.\n"
103 " :type x: float\n"
104 " :arg y: Y coordinate of a 2D point.\n"
105 " :type y: float\n"
106 " :return: The FEdge nearest to the specified 2D point.\n"
107 " :rtype: :class:`FEdge`\n");
108static PyObject *ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
109{
110 static const char *kwlist[] = {"x", "y", nullptr};
111 double x, y;
112
113 if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
114 return nullptr;
115 }
116 FEdge *fe = const_cast<FEdge *>(self->vm->getClosestFEdge(x, y));
117 if (fe) {
118 return Any_BPy_FEdge_from_FEdge(*fe);
119 }
120 Py_RETURN_NONE;
121}
122
123// static ViewMap *getInstance ();
124
125#ifdef __GNUC__
126# ifdef __clang__
127# pragma clang diagnostic push
128# pragma clang diagnostic ignored "-Wcast-function-type"
129# else
130# pragma GCC diagnostic push
131# pragma GCC diagnostic ignored "-Wcast-function-type"
132# endif
133#endif
134
135static PyMethodDef BPy_ViewMap_methods[] = {
136 {"get_closest_viewedge",
137 (PyCFunction)ViewMap_get_closest_viewedge,
138 METH_VARARGS | METH_KEYWORDS,
139 ViewMap_get_closest_viewedge_doc},
140 {"get_closest_fedge",
141 (PyCFunction)ViewMap_get_closest_fedge,
142 METH_VARARGS | METH_KEYWORDS,
143 ViewMap_get_closest_fedge_doc},
144 {nullptr, nullptr, 0, nullptr},
145};
146
147#ifdef __GNUC__
148# ifdef __clang__
149# pragma clang diagnostic pop
150# else
151# pragma GCC diagnostic pop
152# endif
153#endif
154
155/*----------------------ViewMap get/setters ----------------------------*/
156
158 /* Wrap. */
159 ViewMap_scene_bbox_doc,
160 "The 3D bounding box of the scene.\n"
161 "\n"
162 ":type: :class:`BBox`\n");
163static PyObject *ViewMap_scene_bbox_get(BPy_ViewMap *self, void * /*closure*/)
164{
165 return BPy_BBox_from_BBox(self->vm->getScene3dBBox());
166}
167
168static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void * /*closure*/)
169{
170 if (!BPy_BBox_Check(value)) {
171 PyErr_SetString(PyExc_TypeError, "value must be a BBox");
172 return -1;
173 }
174 self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb));
175 return 0;
176}
177
178static PyGetSetDef BPy_ViewMap_getseters[] = {
179 {"scene_bbox",
182 ViewMap_scene_bbox_doc,
183 nullptr},
184 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
185};
186
187/*-----------------------BPy_ViewMap type definition ------------------------------*/
188
189PyTypeObject ViewMap_Type = {
190 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
191 /*tp_name*/ "ViewMap",
192 /*tp_basicsize*/ sizeof(BPy_ViewMap),
193 /*tp_itemsize*/ 0,
194 /*tp_dealloc*/ (destructor)ViewMap_dealloc,
195 /*tp_vectorcall_offset*/ 0,
196 /*tp_getattr*/ nullptr,
197 /*tp_setattr*/ nullptr,
198 /*tp_as_async*/ nullptr,
199 /*tp_repr*/ (reprfunc)ViewMap_repr,
200 /*tp_as_number*/ nullptr,
201 /*tp_as_sequence*/ nullptr,
202 /*tp_as_mapping*/ nullptr,
203 /*tp_hash*/ nullptr,
204 /*tp_call*/ nullptr,
205 /*tp_str*/ nullptr,
206 /*tp_getattro*/ nullptr,
207 /*tp_setattro*/ nullptr,
208 /*tp_as_buffer*/ nullptr,
209 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
210 /*tp_doc*/ ViewMap_doc,
211 /*tp_traverse*/ nullptr,
212 /*tp_clear*/ nullptr,
213 /*tp_richcompare*/ nullptr,
214 /*tp_weaklistoffset*/ 0,
215 /*tp_iter*/ nullptr,
216 /*tp_iternext*/ nullptr,
217 /*tp_methods*/ BPy_ViewMap_methods,
218 /*tp_members*/ nullptr,
219 /*tp_getset*/ BPy_ViewMap_getseters,
220 /*tp_base*/ nullptr,
221 /*tp_dict*/ nullptr,
222 /*tp_descr_get*/ nullptr,
223 /*tp_descr_set*/ nullptr,
224 /*tp_dictoffset*/ 0,
225 /*tp_init*/ (initproc)ViewMap_init,
226 /*tp_alloc*/ nullptr,
227 /*tp_new*/ PyType_GenericNew,
228};
229
#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)
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
PyDoc_STRVAR(ViewMap_doc, "Class defining the ViewMap.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
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