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