Blender V5.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
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
56static void ViewMap_dealloc(BPy_ViewMap *self)
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 " :param x: X coordinate of a 2D point.\n"
75 " :type x: float\n"
76 " :param 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,
86 kwds,
87 "d" /* `x` */
88 "d" /* `y` */
89 ":get_closest_viewedge",
90 (char **)kwlist,
91 &x,
92 &y))
93 {
94 return nullptr;
95 }
96 ViewEdge *ve = const_cast<ViewEdge *>(self->vm->getClosestViewEdge(x, y));
97 if (ve) {
99 }
100 Py_RETURN_NONE;
101}
102
104 /* Wrap. */
105 ViewMap_get_closest_fedge_doc,
106 ".. method:: get_closest_fedge(x, y)\n"
107 "\n"
108 " Gets the FEdge nearest to the 2D point specified as arguments.\n"
109 "\n"
110 " :param x: X coordinate of a 2D point.\n"
111 " :type x: float\n"
112 " :param y: Y coordinate of a 2D point.\n"
113 " :type y: float\n"
114 " :return: The FEdge nearest to the specified 2D point.\n"
115 " :rtype: :class:`FEdge`\n");
116static PyObject *ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
117{
118 static const char *kwlist[] = {"x", "y", nullptr};
119 double x, y;
120
121 if (!PyArg_ParseTupleAndKeywords(args,
122 kwds,
123 "d" /* `x` */
124 "d" /* `y` */
125 ":get_closest_fedge",
126 (char **)kwlist,
127 &x,
128 &y))
129 {
130 return nullptr;
131 }
132 FEdge *fe = const_cast<FEdge *>(self->vm->getClosestFEdge(x, y));
133 if (fe) {
134 return Any_BPy_FEdge_from_FEdge(*fe);
135 }
136 Py_RETURN_NONE;
137}
138
139// static ViewMap *getInstance ();
140
141#ifdef __GNUC__
142# ifdef __clang__
143# pragma clang diagnostic push
144# pragma clang diagnostic ignored "-Wcast-function-type"
145# else
146# pragma GCC diagnostic push
147# pragma GCC diagnostic ignored "-Wcast-function-type"
148# endif
149#endif
150
151static PyMethodDef BPy_ViewMap_methods[] = {
152 {"get_closest_viewedge",
153 (PyCFunction)ViewMap_get_closest_viewedge,
154 METH_VARARGS | METH_KEYWORDS,
155 ViewMap_get_closest_viewedge_doc},
156 {"get_closest_fedge",
157 (PyCFunction)ViewMap_get_closest_fedge,
158 METH_VARARGS | METH_KEYWORDS,
159 ViewMap_get_closest_fedge_doc},
160 {nullptr, nullptr, 0, nullptr},
161};
162
163#ifdef __GNUC__
164# ifdef __clang__
165# pragma clang diagnostic pop
166# else
167# pragma GCC diagnostic pop
168# endif
169#endif
170
171/*----------------------ViewMap get/setters ----------------------------*/
172
174 /* Wrap. */
175 ViewMap_scene_bbox_doc,
176 "The 3D bounding box of the scene.\n"
177 "\n"
178 ":type: :class:`BBox`\n");
179static PyObject *ViewMap_scene_bbox_get(BPy_ViewMap *self, void * /*closure*/)
180{
181 return BPy_BBox_from_BBox(self->vm->getScene3dBBox());
182}
183
184static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void * /*closure*/)
185{
186 if (!BPy_BBox_Check(value)) {
187 PyErr_SetString(PyExc_TypeError, "value must be a BBox");
188 return -1;
189 }
190 self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb));
191 return 0;
192}
193
194static PyGetSetDef BPy_ViewMap_getseters[] = {
195 {"scene_bbox",
198 ViewMap_scene_bbox_doc,
199 nullptr},
200 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
201};
202
203/*-----------------------BPy_ViewMap type definition ------------------------------*/
204
205PyTypeObject ViewMap_Type = {
206 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
207 /*tp_name*/ "ViewMap",
208 /*tp_basicsize*/ sizeof(BPy_ViewMap),
209 /*tp_itemsize*/ 0,
210 /*tp_dealloc*/ (destructor)ViewMap_dealloc,
211 /*tp_vectorcall_offset*/ 0,
212 /*tp_getattr*/ nullptr,
213 /*tp_setattr*/ nullptr,
214 /*tp_as_async*/ nullptr,
215 /*tp_repr*/ (reprfunc)ViewMap_repr,
216 /*tp_as_number*/ nullptr,
217 /*tp_as_sequence*/ nullptr,
218 /*tp_as_mapping*/ nullptr,
219 /*tp_hash*/ nullptr,
220 /*tp_call*/ nullptr,
221 /*tp_str*/ nullptr,
222 /*tp_getattro*/ nullptr,
223 /*tp_setattro*/ nullptr,
224 /*tp_as_buffer*/ nullptr,
225 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
226 /*tp_doc*/ ViewMap_doc,
227 /*tp_traverse*/ nullptr,
228 /*tp_clear*/ nullptr,
229 /*tp_richcompare*/ nullptr,
230 /*tp_weaklistoffset*/ 0,
231 /*tp_iter*/ nullptr,
232 /*tp_iternext*/ nullptr,
233 /*tp_methods*/ BPy_ViewMap_methods,
234 /*tp_members*/ nullptr,
235 /*tp_getset*/ BPy_ViewMap_getseters,
236 /*tp_base*/ nullptr,
237 /*tp_dict*/ nullptr,
238 /*tp_descr_get*/ nullptr,
239 /*tp_descr_set*/ nullptr,
240 /*tp_dictoffset*/ 0,
241 /*tp_init*/ (initproc)ViewMap_init,
242 /*tp_alloc*/ nullptr,
243 /*tp_new*/ PyType_GenericNew,
244};
245
#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)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
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
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 *)
const FEdge * getClosestFEdge(real x, real y) const
Definition ViewMap.cpp:96
const ViewEdge * getClosestViewEdge(real x, real y) const
Definition ViewMap.cpp:116
BBox< Vec3r > getScene3dBBox() const
Definition ViewMap.h:149
void setScene3dBBox(const BBox< Vec3r > &bbox)
Definition ViewMap.h:178
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject_HEAD Freestyle::ViewMap * vm
Definition BPy_ViewMap.h:26